private void work() { using (var scope = _scope.BeginLifetimeScope()) { IJob job = null; try { job = scope.ResolveNamed <IJob>(Describer.InternalName); } catch (Exception ex) { _context.Fatal(ex, $"Can't resolve job {Describer.InternalName} {Describer.Name}"); } try { _context.Info($"Job {Describer.InternalName} {Describer.Name} staring"); job.Execute(_context, _linkedCTS.Token); _context.Info($"Job {Describer.InternalName} {Describer.Name} execute completed"); _q.Enqueue(new Signal(SignalType.JobCompleted, Describer.Name, Describer.InternalName), 1); } catch (Exception ex) { _context.Error(ex, $"Execute job {Describer.InternalName} {Describer.Name} failed"); _q.Enqueue(new Signal(SignalType.JobError, Describer.Name, ex.Message), 1); } } }
public void Execute(IJobContext serviceContext, CancellationToken token) { int count = 10; while (count > 0 && !token.IsCancellationRequested) { serviceContext.Info("I'm doing repeating job {0}", count); Thread.Sleep(TimeSpan.FromSeconds(1)); count--; } }