public async Task ExecuteAsync(TJob job) { using (TaskContext.Enter()) { await jobRunner.RunJobAsync(job, CancellationToken.None); // must await instead of returning, otherwise task context gets disposed too early } }
public async Task ExecuteAsync(TJob job) { using (TaskContext.Enter()) { await jobRunner.RunJobAsync(job); // has to await, otherwise task context gets disposed too early } }
/// <summary> /// Async wrapper for Commerce Worker Role /// </summary> /// <returns> /// A Task to be waited on /// </returns> private async Task RunAsync() { Log.Verbose("Running Commerce Worker role."); Log.Verbose("Checking if we can start processing jobs ..."); while (!ProcessJobs) { // is it fine ? too fast or slow? // we will finetune this after few tries on prod. Thread.Sleep(CommerceWorkerConfig.Instance.ProcessingLoopPollingInterval); } Log.Verbose("Entering processing loop."); do { try { Thread.Sleep(CommerceWorkerConfig.Instance.ProcessingLoopPollingInterval); ScheduledJobDetails jobDetails = await Scheduler.GetJobToProcessAsync(); if (jobDetails != null) { IJobRunner runner = JobRunnerFactory.Runner( jobDetails, Scheduler, CommerceWorkerConfig.Instance, Log); Log.Information("Running {0} job.", jobDetails.JobType); Tuple <IScheduler, ScheduledJobDetails> timerState = new Tuple <IScheduler, ScheduledJobDetails>(Scheduler, jobDetails); using (Timer tmr = new Timer(ExtendTimeout, timerState, WhenToExtendTimeout, WhenToExtendTimeout)) { await runner.RunJobAsync(jobDetails); } } } catch (Exception ex) { Log.Critical("An unknown error occurred during processing.", ex); } }while (ProcessJobs); Log.Information("Processing loop has exited."); // We are no longer processing jobs new now...just waiting to be killed when processing ends. while (!ExitRole) { #if !IntDebug && !IntRelease Log.Information("Wating for role to exit ..."); #endif Thread.Sleep(TimeSpan.FromSeconds(1)); } Log.Information("Role is shutting down ..."); }