public async Task Schedule(JobInfo jobInfo)
 {
     jobInfo.AssertValid();
     this.ResolveJob(jobInfo);
     this.ScheduleNative(jobInfo);
     await this.repository.Set(jobInfo.Identifier, PersistJobInfo.ToPersist(jobInfo));
 }
        protected async Task <JobRunResult> RunJob(JobInfo job, CancellationToken cancelToken)
        {
            this.jobStarted.OnNext(job);
            var result = default(JobRunResult);
            var cancel = false;

            try
            {
                this.LogJob(JobState.Start, job);
                var jobDelegate = this.ResolveJob(job);

                var newData = await jobDelegate
                              .Run(job, cancelToken)
                              .ConfigureAwait(false);

                if (!job.Repeat)
                {
                    await this.Cancel(job.Identifier);

                    cancel = true;
                }
                this.LogJob(JobState.Finish, job);
                result = new JobRunResult(newData, job, null);
            }
            catch (Exception ex)
            {
                this.LogJob(JobState.Error, job, ex);
                result = new JobRunResult(false, job, ex);
            }
            finally
            {
                if (!cancel)
                {
                    job.LastRunUtc = DateTime.UtcNow;
                    await this.repository.Set(job.Identifier, PersistJobInfo.ToPersist(job));
                }
            }
            this.jobFinished.OnNext(result);
            return(result);
        }
Example #3
0
 public async Task Register(JobInfo jobInfo)
 {
     this.ResolveJob(jobInfo);
     this.RegisterNative(jobInfo);
     await this.repository.Set(jobInfo.Identifier, PersistJobInfo.ToPersist(jobInfo));
 }