public void Schedule <T>(IScheduledJob <T> job, DateTimeOffset nextTime) where T : IJob { _statusMonitor.MarkScheduled <T>(nextTime); _timer.Schedule(typeof(T), nextTime, () => job.Execute(this)); _logger.InfoMessage(() => new ScheduledJobScheduled(typeof(T), nextTime)); }
public void ProcessJob(object state) { TriggerFiredBundle bundle = state as TriggerFiredBundle; Trigger trigger = bundle.Trigger; IScheduledJob job = bundle.Job; while (true) { JobExecutionException result = null; ScheduledJobContext context = new ScheduledJobContext(); try { job.Execute(context); } catch (JobExecutionException exception2) { result = exception2; log.Info(string.Format(CultureInfo.InvariantCulture, "Job {0} threw a JobExecutionException: ", new object[] { job.Name }), exception2); } catch (Exception exception3) { log.Error(string.Format(CultureInfo.InvariantCulture, "Job {0} threw an unhandled Exception: ", new object[] { job.Name }), exception3); SchedulerException cause = new SchedulerException("Job threw an unhandled exception.", exception3) { ErrorCode = 800 }; result = new JobExecutionException(cause, false) { ErrorCode = 800 }; } SchedulerInstruction noInstruction = SchedulerInstruction.NoInstruction; try { noInstruction = trigger.ExecutionComplete(context, result); } catch (Exception) { } if (noInstruction == SchedulerInstruction.ReExecuteJob) { if (log.get_IsDebugEnabled()) { log.Debug("Rescheduling trigger to reexecute"); } } else { this.TriggeredJobComplete(trigger, job, noInstruction); break; } } this.NotifySchedulerThread(); }
private void ExecuteJob(IScheduledJob job, CancellationToken token) { var name = job.GetType().Name; _config?.OnJobStart?.Invoke(name); Start(); job.Execute(token); Stop(); _config?.OnJobEnd?.Invoke(name); }
public void ProcessJob(object state) { TriggerFiredBundle bundle = state as TriggerFiredBundle; Trigger trigger = bundle.Trigger; IScheduledJob job = bundle.Job; do { JobExecutionException jobExecutionException = null; ScheduledJobContext scheduledJobContext = new ScheduledJobContext(); try { job.Execute(scheduledJobContext); } catch (JobExecutionException jee) { jobExecutionException = jee; log.Info(string.Format(CultureInfo.InvariantCulture, "Job {0} threw a JobExecutionException: ", job.Name), jee); } catch (Exception ex) { log.Error(string.Format(CultureInfo.InvariantCulture, "Job {0} threw an unhandled Exception: ", job.Name), ex); SchedulerException se = new SchedulerException("Job threw an unhandled exception.", ex); se.ErrorCode = SchedulerException.ErrorJobExecutionThrewException; jobExecutionException = new JobExecutionException(se, false); jobExecutionException.ErrorCode = JobExecutionException.ErrorJobExecutionThrewException; } SchedulerInstruction instCode = SchedulerInstruction.NoInstruction; try { instCode = trigger.ExecutionComplete(scheduledJobContext, jobExecutionException); } catch (Exception) { // If this happens, there's a bug in the trigger... } // update job/trigger or re-Execute job if (instCode == SchedulerInstruction.ReExecuteJob) { if (log.IsDebugEnabled) { log.Debug("Rescheduling trigger to reexecute"); } continue; } TriggeredJobComplete(trigger, job, instCode); break; } while (true); NotifySchedulerThread(); }
/// <summary> /// Excute the job /// </summary> /// <param name="job"> /// The job to execute /// </param> /// <param name="details"> /// Job Details /// </param> /// <returns> /// Async Task Wrapper /// </returns> internal async Task ExecuteJob(IScheduledJob job, ScheduledJobDetails details) { try { await job.Execute(details, Log); } catch (Exception exception) { Log.Error(" Error in execution job \r\n" + " Details : {0}", exception, (int)ResultCode.JobExecutionError, details); } }
public void ExecuteNow(IScheduledJob job) { job.Execute(this); }