protected bool DoRetry(out JobResult result) { result = null; if (CurrentRetry < Times) { CurrentRetry++; result = ErrorHandle.Expect(() => { return _job.Doable(); }, out bool anyError, _msgError, string.Format(_msgJobError, Id.Id, Id.Name), string.Format(_msgRetryError, CurrentRetry, Times)); if (anyError) { result = new JobResult(JobStatus.CompletedWithError, new AutoJobException(_job.Id, null, string.Format(_msgRetryError, CurrentRetry, Times))); } } else return true; if (Interval == TimeSpan.Zero) return false; return result.Status == JobStatus.Completed; }
private bool Validate() { if (BeforeRetry == null) return true; var rs = ErrorHandle.Expect( () => { return BeforeRetry(_job.Context); }, out bool anyError, string.Format(_msgValidationFailure, CurrentRetry)); return !(rs == ValidationResult.NotValid || anyError); }
private JobResult Run(IAutomatedJob job) { JobResult result = null; result = ErrorHandle.Expect(() => job.Doable(), out bool anyError, string.Format(_msgWError, Current.Id.Id, Current.Id.Name), string.Format(_msgJobError, job.Id.Id, job.Id.Name)); if (anyError) { result = new JobResult(JobStatus.CompletedWithError, new AutoJobException(job.Id, null, _msgError)); } _jobStatus[job.Id.ToString()] = result; return(result); }
private void Push(JobId senderKey, MessageHook message, HookNotification h) { ErrorHandle.Expect(() => { h.Handler.DoHandle(senderKey, message); return(true); }, out bool anyError, string.Format(_errorInHanlder, senderKey.Id, senderKey.Name, message.Type, h.Handler.Id, h.Handler.Name), string.Format(_errorMessage, message.Text)); }
/// <summary> /// wrap the retry functionality into the given job. /// </summary> /// <returns></returns> public virtual JobResult Doable() { JobResult rtn = null; Mutex[] m = new Mutex[2] { _job.mLock, mLock }; if (Mutex.WaitAll(m)) { rtn = ErrorHandle.Expect(Invoke, out bool anyError, string.Format(_msgJobError, Id.Id, Id.Name), _msgError); foreach (var mtx in m) { mtx.ReleaseMutex(); } if(anyError) rtn = new JobResult(_retryResults.Last().Status); } rtn = rtn?? new JobResult(_retryResults.Last().Status); return rtn; }