public async Task <bool> DeleteAsync(string jobId) { BackgroundJobInfo jobInfo = await _store.GetAsync(jobId); if (jobInfo == null) { return(false); } await _store.DeleteAsync(jobInfo); return(true); }
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)); } var jobInfo = await _store.GetAsync(finalJobId); await _store.DeleteAsync(jobInfo); return(true); }
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().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 AbpHandledExceptionData( 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 } ) ); } } } catch (Exception ex) { Logger.Warn(ex.ToString(), ex); jobInfo.IsAbandoned = true; TryUpdate(jobInfo); } }
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().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); } } } catch (Exception ex) { Logger.Warn(ex.ToString(), ex); jobInfo.IsAbandoned = true; TryUpdate(jobInfo); } }