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); }
public async Task Cancel(string jobIdentifier) { var job = await this.repository.Get <PersistJobInfo>(jobIdentifier); if (job != null) { this.CancelNative(PersistJobInfo.FromPersist(job)); await this.repository.Remove <PersistJobInfo>(jobIdentifier); } }
public async Task <JobInfo?> GetJob(string jobName) { var job = await this.repository.Get <PersistJobInfo>(jobName); if (job == null) { return(null); } return(PersistJobInfo.FromPersist(job)); }
public virtual async Task CancelAll() { var jobs = await this.repository.GetAllWithKeys <PersistJobInfo>(); foreach (var job in jobs) { if (!job.Value.IsSystemJob) { this.CancelNative(PersistJobInfo.FromPersist(job.Value)); await this.repository.Remove <PersistJobInfo>(job.Key); } } }
public async Task <IEnumerable <JobRunResult> > RunAll(CancellationToken cancelToken, bool runSequentially) { var list = new List <JobRunResult>(); if (!this.IsRunning) { try { this.IsRunning = true; var jobs = await this.repository.GetAll <PersistJobInfo>(); var tasks = new List <Task <JobRunResult> >(); if (runSequentially) { foreach (var job in jobs) { var actual = PersistJobInfo.FromPersist(job); var result = await this .RunJob(actual, cancelToken) .ConfigureAwait(false); list.Add(result); } } else { foreach (var job in jobs) { var actual = PersistJobInfo.FromPersist(job); tasks.Add(this.RunJob(actual, cancelToken)); } await Task .WhenAll(tasks) .ConfigureAwait(false); list.AddRange(tasks.Select(x => x.Result)); } } catch (Exception ex) { Log.Write(ex); } finally { this.IsRunning = false; } } return(list); }