/// <summary> /// Log error that was thrown in a hangfire job /// </summary> /// <param name="cancellationToken">The cancellation token</param> /// <returns>The response</returns> public Task Execute(CancellationToken cancellationToken) { if (_logger.IsErrorEnabled) { return(ExecuteWithErrorLogging(cancellationToken)); } else { return(_handler.Execute(cancellationToken)); } }
/// <summary> /// 异步执行任务 把任务插入线程任务队列中排队执行 /// </summary> /// <param name="jobInfo"></param> /// <param name="jobHandler"></param> /// <returns></returns> private async Task AsyncExecuteJob(JobRunRequest jobInfo, IJobHandler jobHandler) { Func <object, Task> action = async(state) => { if (jobInfo.JobStatus == JobStatus.Killed) //已终止的任务 就不要再运行了 { _logger.LogInformation($"**************该任务已被终止 {jobInfo.jobId},{jobInfo.logId}********************"); return; } jobInfo.SetRunning(); ReturnT executeResult = null; try { executeResult = await jobHandler.Execute(new JobExecuteContext(jobInfo.logId, jobInfo.executorParams)); } catch (Exception ex) { executeResult = ReturnT.Failed(ex.StackTrace + "————" + ex.Message); _logger.LogError(ex, "xxljob执行任务错误"); } _xxlJobExecutor.RemoveJobInfo(jobInfo); await CallBack(jobInfo.logId, executeResult); //这里保证一定要回调结果 不然就要重试了(配置了重试次数),这里回调为失败结果也会重试(配置了重试次数) }; _xxlJobExecutor.RegistJobInfo(jobInfo); //插入任务执行队列中 根据jobid路由到固定线程中 保证同一个jobid串行执行 _taskExecutor.GetSingleThreadTaskExecutor(jobInfo.jobId).Execute(action, null); await Task.CompletedTask; }
/// <summary> /// /// </summary> /// <param name="jobEntity"></param> protected internal virtual void ExecuteJobHandler(IJobEntity jobEntity) { IExecutionEntity execution = null; if (!(jobEntity.ExecutionId is null)) { execution = ExecutionEntityManager.FindById <ExecutionEntityImpl>(jobEntity.ExecutionId); } IDictionary <string, IJobHandler> jobHandlers = processEngineConfiguration.JobHandlers; IJobHandler jobHandler = jobHandlers[jobEntity.JobHandlerType]; jobHandler.Execute(jobEntity, jobEntity.JobHandlerConfiguration, execution, CommandContext); }
/// <summary> /// Execute job /// </summary> /// <param name="cancellationToken">The cancellation token</param> /// <returns>The task</returns> public async Task Execute(CancellationToken cancellationToken) { try { await _handler .Execute(cancellationToken) .ConfigureAwait(Await.Default); } catch (OperationCanceledException) { throw; } #pragma warning disable CA1031 catch (Exception) #pragma warning restore CA1031 { } }
/// <summary> /// Execute log /// </summary> /// <param name="cancellationToken">The cancellation token</param> /// <returns>The response</returns> public async Task Execute(CancellationToken cancellationToken) { bool isInfoEnabled = _logger.IsInfoEnabled; if (isInfoEnabled == true) { _logger.InfoFormat("Executing {0}", typeof(T).Name); } await _handler .Execute(cancellationToken) .ConfigureAwait(Await.Default); if (isInfoEnabled == true) { _logger.InfoFormat("Executed {0}", typeof(T).Name); } }
private async Task WaitJob() { _switch.SetStateAction(DoNothing); var job = await _krakerApi.GetJob(_agentId); _logger.Information("Got a job {0}", job); if (job == null || job is IncorrectJob or DoNothingJob) { _switch.SetStateAction(WaitJob); return; } _jobHandler = _jobHandlerProvider.Get(job); _jobHandler.Execute(); _switch.SetStateAction(ProcessJob); }
public virtual void Execute(CommandContext commandContext) { if (ExecutionId != null) { ExecutionEntity exec = Execution; EnsureUtil.EnsureNotNull("Cannot find execution with id '" + ExecutionId + "' referenced from job '" + this + "'", "execution", exec); } // initialize activity id GetActivityId(); // increment sequence counter before job execution IncrementSequenceCounter(); PreExecute(commandContext); IJobHandler jobHandler = JobHandler; IJobHandlerConfiguration configuration = JobHandlerConfiguration; EnsureUtil.EnsureNotNull("Cannot find job handler '" + JobHandlerType + "' from job '" + this + "'", "jobHandler", jobHandler); jobHandler.Execute(configuration, execution, commandContext, TenantId); PostExecute(commandContext); }
/// <summary> /// Execute download integration export job /// </summary> /// <param name="cancellationToken">The cancellation token</param> /// <returns>The response</returns> public Task Execute(CancellationToken cancellationToken) { return(_handler.Execute(cancellationToken)); }