public JobRunner(JobRunnerContext context) { _context = context ?? throw new ArgumentNullException(nameof(context)); _runningTask = null; _stoppingTask = null; _lastLoop = InstantUtils.Now; }
private void RecycleRunner(JobRunnerContext subscription) { // Create a new JobRunner for the subscription anyway. // If there's a runner present, replace it and stop the original one. _runners.AddOrUpdate(subscription.Id, id => { // addValueFactory; If the value is not present in the dictionary var newRunner = new JobRunner(subscription); newRunner.Start(null); return(newRunner); }, (id, runner) => { // updateValueFactory; If there is a runner in the dictionary // Stop the currently-running (probably already dead) runner to make sure it doesn't // come back to life and cause problems if (runner.Running) { runner.Stop(); } var newRunner = new JobRunner(subscription); newRunner.Start(null); return(newRunner); }); }
private void CheckJobLiveliness(JobRunnerContext subscription) { if (!_runners.TryGetValue(subscription.Id, out var runner)) { _logger.Information("No JobRunner for {SubscriptionId} yet, starting one.", subscription.Id); RecycleRunner(subscription); return; } if (!runner.Running && !_stopping) { _logger.Warning("JobRunner for {SubscriptionId} appears to be stopped. Recycling.", subscription.Id); RecycleRunner(subscription); } if (runner.MillisSinceLastLoop > Timing.Monitor.SecondsBeforeConsiderRunningJobUnresponsive * 1000) { _logger.Warning("JobRunner for {SubscriptionId} is not responding. Recycling.", subscription.Id); RecycleRunner(subscription); } }
public JobIteration(JobRunnerContext context, JobProgress currentProgress) { _context = context ?? throw new ArgumentNullException(nameof(context)); Progress = currentProgress; }