public BackgroundWorkerContinuation Work(BackgroundWorkerContext context, CancellationToken token) { if (token.IsCancellationRequested) { return(context.Exit()); } if (context.InvocationCount == 1) { foreach (BackgroundServerHost host in _servers) { try { host.Start(); _isRunning.Add(host); } catch (Exception ex) { LogError(host, ex); } } _output($"Started {_isRunning.Count} server(s)"); return(context.Wait(_configuration.HouseKeepingInterval)); } // Calculates whether to output status text or not, depending on number of iterations. bool outputStatus = _configuration.OutputStatusText(context.InvocationCount); CheckIsRunning(outputStatus); if (ExitHouseKeeping()) { _output("Exiting (no more servers left to monitor)"); Dispose(); return(context.Exit()); } if (outputStatus) { _output($"{_isRunning.Count} server(s) running. Uptime: {_uptime.GetUptimeText(_startedAt)}"); } return(context.Wait(_configuration.HouseKeepingInterval)); }
public BackgroundWorkerContinuation Work(BackgroundWorkerContext context, CancellationToken token) { context.Console.WriteLine($"Sending message from Worker {context.InvocationCount}"); _bus.Send($"Hello {context.InvocationCount}").Wait(token); return(context.Wait(TimeSpan.FromSeconds(5))); }
public BackgroundWorkerContinuation Work(BackgroundWorkerContext context, CancellationToken token) { Request(context, token, "hello"); Request(context, token, "custom/url/route"); Request(context, token, "custom/url/route/different"); return(context.Wait(TimeSpan.FromSeconds(5))); }
public BackgroundWorkerContinuation Work(BackgroundWorkerContext context, CancellationToken token) { if (context.InvocationCount == 10) { return(context.Exit()); } return(context.Wait(TimeSpan.FromSeconds(1))); }
public BackgroundWorkerContinuation Work(BackgroundWorkerContext context, CancellationToken token) { if (context.InvocationCount < 5u) { throw new InvalidOperationException(); } context.Console.WriteLine($"{nameof(MyOtherWorker)}: Invocation#: {context.InvocationCount}"); return(context.Wait(TimeSpan.FromSeconds(2))); }
public BackgroundWorkerContinuation Work(BackgroundWorkerContext context, CancellationToken token) { var message = $"A message from the \"Fire and forget\"-worker (#{context.InvocationCount}) - containing {{json}}"; BackgroundJob.Enqueue <IHangfireJob>(x => x.WriteMessageToTheConsoleWriter(message)); const string anotherMessage = "A different message from the \"Fire and forget\"-worker (#{0}) - containing string format"; BackgroundJob.Enqueue <IHangfireJob>(x => x.WriteMessageToTheConsoleWriter(anotherMessage, context.InvocationCount)); return(context.Wait(TimeSpan.FromSeconds(10))); }
public BackgroundWorkerContinuation Work(BackgroundWorkerContext context, CancellationToken token) { var logEntry = new HeartbeatLogEntry(Time.UtcNow); foreach (IHeartbeatProvider provider in _providers) { logEntry.CollectFrom(provider, token); } _repository.Insert(logEntry); return(context.Wait(_interval)); }
public BackgroundWorkerContinuation Work(BackgroundWorkerContext context, CancellationToken token) { //BackgroundJob.Enqueue<ISomeInterfaceMissingImplementation>(x => x.CallMeAndHangfireWillThrowException()); return(context.Wait(TimeSpan.FromSeconds(7))); }
public BackgroundWorkerContinuation Work(BackgroundWorkerContext context, CancellationToken token) { context.Console.WriteLine($"{nameof(MyOtherWorker)}: Invocation#: {context.InvocationCount}"); return(context.Wait(TimeSpan.FromSeconds(2))); }
public BackgroundWorkerContinuation Work(BackgroundWorkerContext context, CancellationToken token) { context.Console.WriteLine($"Hello #{context.InvocationCount}"); return(context.Wait(TimeSpan.FromSeconds(10))); }