public void StartJobRun(TriggeredJob triggeredJob, JobSettings jobSettings, string trigger, Action <string, string> reportAction) { JobSettings = jobSettings; if (Settings.IsWebJobsStopped()) { throw new WebJobsStoppedException(); } if (!_lockFile.Lock()) { throw new ConflictException(); } TriggeredJobRunLogger logger = TriggeredJobRunLogger.LogNewRun(triggeredJob, trigger, Environment, TraceFactory, Settings); Debug.Assert(logger != null); try { if (_currentRunningJobWaitHandle != null) { _currentRunningJobWaitHandle.Dispose(); _currentRunningJobWaitHandle = null; } _currentRunningJobWaitHandle = new ManualResetEvent(false); var tracer = TraceFactory.GetTracer(); var step = tracer.Step("Run {0} {1}", triggeredJob.JobType, triggeredJob.Name); ThreadPool.QueueUserWorkItem(_ => { try { InitializeJobInstance(triggeredJob, logger); RunJobInstance(triggeredJob, logger, logger.Id, trigger, tracer); } catch (Exception ex) { logger.LogError("WebJob run failed due to: " + ex); } finally { step.Dispose(); logger.ReportEndRun(); _lockFile.Release(); reportAction(triggeredJob.Name, logger.Id); _currentRunningJobWaitHandle.Set(); } }); } catch (Exception ex) { logger.LogError("Failed to start job due to: " + ex); _lockFile.Release(); throw; } }
public void StartJobRun(TriggeredJob triggeredJob) { if (Settings.IsWebJobsStopped()) { throw new WebJobsStoppedException(); } if (!_lockFile.Lock()) { throw new ConflictException(); } TriggeredJobRunLogger logger = TriggeredJobRunLogger.LogNewRun(triggeredJob, Environment, TraceFactory, Settings); Debug.Assert(logger != null); try { InitializeJobInstance(triggeredJob, logger); ThreadPool.QueueUserWorkItem(_ => { try { RunJobInstance(triggeredJob, logger, logger.Id); } finally { logger.ReportEndRun(); _lockFile.Release(); } }); } catch (Exception ex) { logger.LogError("Failed to start job due to: " + ex); _lockFile.Release(); throw; } }