public Task InsertAsync(BackgroundJobInfo jobInfo) { jobInfo.Id = Interlocked.Increment(ref _lastId); _jobs[jobInfo.Id] = jobInfo; return(Task.FromResult(0)); }
public Task UpdateAsync(BackgroundJobInfo jobInfo) { if (jobInfo.IsAbandoned) { return(DeleteAsync(jobInfo)); } return(Task.FromResult(0)); }
private void TryUpdate(BackgroundJobInfo jobInfo) { try { _store.UpdateAsync(jobInfo); } catch (Exception updateEx) { Logger.Warn(updateEx.ToString(), updateEx); } }
public async Task <bool> DeleteAsync(string jobId) { if (long.TryParse(jobId, out long finalJobId) == false) { throw new ArgumentException($"The jobId '{jobId}' should be a number.", nameof(jobId)); } BackgroundJobInfo jobInfo = await _store.GetAsync(finalJobId); if (jobInfo == null) { return(false); } await _store.DeleteAsync(jobInfo); return(true); }
public async Task <string> EnqueueAsync <TJob, TArgs>(TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan?delay = null) where TJob : IBackgroundJob <TArgs> { var jobInfo = new BackgroundJobInfo { JobType = typeof(TJob).AssemblyQualifiedName, JobArgs = args.ToJsonString(), Priority = priority }; if (delay.HasValue) { jobInfo.NextTryTime = Clock.Now.Add(delay.Value); } await _store.InsertAsync(jobInfo); return(jobInfo.Id.ToString()); }
public Task DeleteAsync(BackgroundJobInfo jobInfo) { _jobs.TryRemove(jobInfo.Id, out _); return(Task.FromResult(0)); }
private void TryProcessJob(BackgroundJobInfo jobInfo) { try { jobInfo.TryCount++; jobInfo.LastTryTime = Clock.Now; var jobType = Type.GetType(jobInfo.JobType); using (var job = _iocResolver.ResolveAsDisposable(jobType)) { try { var jobExecuteMethod = job.Object.GetType().GetTypeInfo().GetMethod("Execute"); var argsType = jobExecuteMethod.GetParameters()[0].ParameterType; var argsObj = JsonConvert.DeserializeObject(jobInfo.JobArgs, argsType); jobExecuteMethod.Invoke(job.Object, new[] { argsObj }); AsyncHelper.RunSync(() => _store.DeleteAsync(jobInfo)); } catch (Exception ex) { Logger.Warn(ex.Message, ex); var nextTryTime = jobInfo.CalculateNextTryTime(); if (nextTryTime.HasValue) { jobInfo.NextTryTime = nextTryTime.Value; } else { jobInfo.IsAbandoned = true; } TryUpdate(jobInfo); EventBus.Trigger( this, new MajidHandledExceptionData( new BackgroundJobException( "A background job execution is failed. See inner exception for details. See BackgroundJob property to get information on the background job.", ex ) { BackgroundJob = jobInfo, JobObject = job.Object } ) ); } } } catch (Exception ex) { Logger.Warn(ex.ToString(), ex); jobInfo.IsAbandoned = true; TryUpdate(jobInfo); } }
public Task UpdateAsync(BackgroundJobInfo jobInfo) { return(Task.FromResult(0)); }
public Task InsertAsync(BackgroundJobInfo jobInfo) { return(Task.FromResult(0)); }
public Task UpdateAsync(BackgroundJobInfo jobInfo) { return(_backgroundJobRepository.UpdateAsync(jobInfo)); }
public Task DeleteAsync(BackgroundJobInfo jobInfo) { return(_backgroundJobRepository.DeleteAsync(jobInfo)); }
public Task InsertAsync(BackgroundJobInfo jobInfo) { return(_backgroundJobRepository.InsertAsync(jobInfo)); }