public Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException, CancellationToken cancellationToken = new CancellationToken()) { return(Task.Run(() => { var jobInfo = context.GetJobInfo(); if (jobInfo != null) { var logger = LogManager.GetLogger(jobInfo.Group, jobInfo.Name); if (jobException != null) { jobInfo.ActionState = JobActionState.Failed.ToString(); logger.Warn(jobException.GetBaseException()); OnExecutionFailed(jobInfo); } else { jobInfo.ActionState = JobActionState.Succeeded.ToString(); OnExecutionSucceeded(jobInfo); logger.Info($"The job '{jobInfo.Group}.{jobInfo.Name}' has been executed successfully"); } OnExecuted(jobInfo); } }, cancellationToken)); }
public async Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException, CancellationToken cancellationToken = new CancellationToken()) { try { if (jobException != null) { jobException.UnscheduleAllTriggers = true; } var jobKey = context.JobDetail.Key.Name; using (var client = DbFactory.CreateClient()) { var scheduleTask = await client.Queryable <ScheduleTask>() .SingleAsync(t => t.JobKey == jobKey); if (scheduleTask != null) { if (jobException == null) { scheduleTask.Status = TaskRunningStatus.Running; scheduleTask.StatusDesc = ""; scheduleTask.LastEndTime = DateTime.Now; scheduleTask.LastSuccessTime = DateTime.Now; } else { scheduleTask.Status = TaskRunningStatus.Error; scheduleTask.StatusDesc = jobException.GetBaseException()?.Message ?? ""; scheduleTask.LastEndTime = DateTime.Now; scheduleTask.IsEnable = false; } await client.Updateable(scheduleTask).UpdateColumns(t => new { t.Status, t.StatusDesc, t.LastEndTime, t.LastSuccessTime, t.IsEnable }).ExecuteCommandAsync(); } } } catch (Exception e) { // ignored } await Task.CompletedTask; }
public async Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException, CancellationToken cancellationToken = default(CancellationToken)) { var entry = await _store.Get(context.FireInstanceId); if (entry != null) { entry.FinishedTimeUtc = DateTime.UtcNow; entry.ExceptionMessage = jobException?.GetBaseException()?.Message; await _store.Save(entry); } if (jobException == null) { await _store.IncrementTotalJobsExecuted(); } else { await _store.IncrementTotalJobsFailed(); } }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="jobException"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public Task UpdateJobHistoryEntryError(IJobExecutionContext context, JobExecutionException jobException, CancellationToken cancellationToken) { lock (_data) { //var entry = await GetJobHistoryEntry(context.Scheduler.SchedulerName, context.FireInstanceId); var entry = _data.Where(p => p.SchedulerName.Equals(context.Scheduler.SchedulerName) && p.FireInstanceId.Equals(context.FireInstanceId)).FirstOrDefault(); if (entry != null) { entry.FinishedTimeUtc = DateTime.UtcNow; entry.ErrorMessage = jobException?.GetBaseException()?.Message; entry.Error = jobException != null; //await Create(entry); } return(Task.CompletedTask); //if (jobException == null) // await IncrementTotalJobsExecuted(context.Scheduler.SchedulerName); //else // await IncrementTotalJobsFailed(context.Scheduler.SchedulerName); } }
public async Task UpdateJobHistoryEntryError( IJobExecutionContext context, JobExecutionException jobException, CancellationToken cancellationToken = default(CancellationToken)) { string sql = AdoJobStoreUtil.ReplaceTablePrefix(PropertySqlUpdateHistoryError, _tablePrefix, null); using (ConnectionAndTransactionHolder connection = GetConnection(IsolationLevel.ReadUncommitted)) { using (DbCommand command = Delegate.PrepareCommand(connection, sql)) { Delegate.AddCommandParameter(command, "error", Delegate.GetDbBooleanValue(jobException != null)); Delegate.AddCommandParameter(command, "errorMessage", jobException?.GetBaseException()?.Message); Delegate.AddCommandParameter(command, "fireInstanceId", context.FireInstanceId); await command.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false); connection.Commit(false); } } }
public async Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException, CancellationToken cancellationToken = default) { var entry = await _store.Get(context.FireInstanceId); if (entry != null) { entry.FinishedTime = DateTime.Now; var exception = jobException?.GetBaseException(); if (exception != null) { entry.ExceptionMessage = exception.Message; entry.ExceptionDetail = exception.ToString(); } await _store.Save(entry); } if (jobException == null) { await _store.IncrementTotalJobsExecuted(); } else { await _store.IncrementTotalJobsFailed(); } }