Esempio n. 1
0
        public virtual async Task <JobRunResult> Run(string jobName, CancellationToken cancelToken)
        {
            JobRunResult result;
            JobInfo?     actual = null;

            try
            {
                var job = await this.repository.Get <PersistJobInfo>(jobName);

                if (job == null)
                {
                    throw new ArgumentException("No job found named " + jobName);
                }

                actual = PersistJobInfo.FromPersist(job);
                result = await this.RunJob(actual, cancelToken).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Log.Write(ex);
                result = new JobRunResult(false, actual, ex);
            }

            return(result);
        }
Esempio n. 2
0
        public virtual async Task <JobRunResult> Run(string jobName, CancellationToken cancelToken)
        {
            JobRunResult result = default;

            try
            {
                var job = await this.Repository.Get <JobInfo>(jobName);

                if (job == null)
                {
                    throw new ArgumentException("No job found named " + jobName);
                }

                result = await this.RunJob(job, cancelToken).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Log.Write(ex);
                result = new JobRunResult(false, new JobInfo
                {
                    Identifier = jobName
                }, ex);
            }

            return(result);
        }
Esempio n. 3
0
        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);
        }