/// <inheritdoc /> public void Execute(BackgroundProcessContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var jobsEnqueued = 0; while (EnqueueNextRecurringJobs(context)) { jobsEnqueued++; if (context.IsStopping) { break; } } if (jobsEnqueued != 0) { _logger.Debug($"{jobsEnqueued} recurring job(s) enqueued."); } if (_pollingDelay > TimeSpan.Zero) { context.Wait(_pollingDelay); } else { var now = _nowFactory(); context.Wait(now.AddMilliseconds(-now.Millisecond).AddSeconds(-now.Second).AddMinutes(1) - now); } }
/// <inheritdoc /> public void Execute(BackgroundProcessContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } int jobsProcessed; do { jobsProcessed = EnqueueNextRecurringJobs(context); if (jobsProcessed != 0) { _logger.Debug($"{jobsProcessed} recurring job(s) processed by scheduler."); } } while (jobsProcessed > 0 && !context.IsStopping); if (_pollingDelay > TimeSpan.Zero) { context.Wait(_pollingDelay); } else { var now = _nowFactory(); context.Wait(now.AddMilliseconds(-now.Millisecond).AddSeconds(-now.Second).AddMinutes(1) - now); } }
/// <inheritdoc /> public void Execute(BackgroundProcessContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var jobsEnqueued = 0; while (EnqueueNextScheduledJob(context)) { jobsEnqueued++; if (context.IsShutdownRequested) { break; } } if (jobsEnqueued != 0) { Logger.Info($"{jobsEnqueued} scheduled job(s) enqueued."); } if (_schedulerEvent == null) { context.Wait(_pollingDelay); } else { WaitHandle.WaitAny(new[] { context.CancellationToken.WaitHandle, _schedulerEvent }, _pollingDelay); } }
/// <inheritdoc /> public void Execute(BackgroundProcessContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var jobsEnqueued = 0; while (EnqueueNextScheduledJob(context)) { jobsEnqueued++; if (context.IsShutdownRequested) { break; } } if (jobsEnqueued != 0) { _logger.Info($"{jobsEnqueued} scheduled job(s) enqueued."); } context.Wait(_pollingDelay); }
public void Execute(BackgroundProcessContext context) { _logger.Trace("Checking for aborted jobs..."); using (var connection = context.Storage.GetConnection()) { var abortedJobIds = ServerJobCancellationToken.CheckAllCancellationTokens( context.ServerId, connection, context.StoppedToken); var aborted = false; foreach (var abortedJobId in abortedJobIds) { _logger.Debug($"Job {abortedJobId.Item1} was aborted on worker {abortedJobId.Item2}."); aborted = true; } if (!aborted) { _logger.Trace("No newly aborted jobs found."); } } context.Wait(_checkInterval); }
public void Execute(BackgroundProcessContext context) { using (var connection = context.Storage.GetConnection()) { connection.Heartbeat(context.ServerId); } context.Wait(_heartbeatInterval); }
public void Execute(BackgroundProcessContext context) { using (var connection = context.Storage.GetConnection()) { connection.Heartbeat(context.ServerId); } context.Wait(_heartbeatInterval);; }
public void Execute(BackgroundProcessContext context) { using (var connection = context.Storage.GetConnection()) { var serversRemoved = connection.RemoveTimedOutServers(_serverTimeout); if (serversRemoved != 0) { Logger.Info($"{serversRemoved} servers were removed due to timeout"); } } context.Wait(_checkInterval); }
public void Execute(BackgroundProcessContext context) { using (var connection = context.Storage.GetConnection()) { var serversRemoved = connection.RemoveTimedOutServers(_serverTimeout); if (serversRemoved != 0) { Logger.Info($"{serversRemoved} servers were removed due to timeout"); } } context.Wait(_checkInterval); }
/// <inheritdoc /> public void Execute(BackgroundProcessContext context) { if (context == null) throw new ArgumentNullException(nameof(context)); int jobsProcessed; do { jobsProcessed = EnqueueNextScheduledJobs(context); if (jobsProcessed != 0) { _logger.Debug($"{jobsProcessed} scheduled job(s) processed by scheduler."); } } while (jobsProcessed > 0 && !context.IsStopping); context.Wait(_pollingDelay); }
public void Execute(BackgroundProcessContext context) { for (var i = 0; i <= MaxRetryAttempts; i++) { try { _innerProcess.Execute(context); return; } catch (OperationCanceledException) { throw; } catch (Exception ex) { // Break the loop after the retry attempts number exceeded. if (i >= MaxRetryAttempts - 1) { throw; } var nextTry = DelayCallback(i); var logLevel = GetLogLevel(i); _logger.Log( logLevel, () => String.Format( "Error occurred during execution of '{0}' process. Execution will be retried (attempt {1} of {2}) in {3} seconds.", _innerProcess, i + 1, MaxRetryAttempts, nextTry), ex); context.Wait(nextTry); if (context.IsShutdownRequested) { break; } } } }
/// <inheritdoc /> public void Execute(BackgroundProcessContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var jobsEnqueued = 0; foreach (var queueName in _queues) { using (var connection = context.Storage.GetConnection()) using (connection.AcquireDistributedLock($"locks:schedulepoller:{ queueName }", DefaultLockTimeout)) { var timestamp = JobHelper.ToTimestamp(DateTime.UtcNow); var jobs = connection.GetAllValuesWithScoresFromSetQueueWithinScoreRange("schedule", queueName, 0, timestamp); if (jobs != null) { foreach (string jobId in jobs.OrderBy(x => x.Value).Select(x => x.Key)) { EnqueueNextScheduledJob(jobId, context, connection, queueName); jobsEnqueued++; if (context.IsShutdownRequested) { break; } } } } } if (jobsEnqueued != 0) { Logger.Info($"{jobsEnqueued} scheduled job(s) enqueued."); } context.Wait(_pollingDelay); }
public void Execute(BackgroundProcessContext context) { for (var i = 0; i <= MaxRetryAttempts; i++) { try { _innerProcess.Execute(context); return; } catch (OperationCanceledException) { throw; } catch (Exception ex) { // Break the loop after the retry attempts number exceeded. if (i >= MaxRetryAttempts - 1) throw; var nextTry = DelayCallback(i); var logLevel = GetLogLevel(i); _logger.Log( logLevel, () => String.Format( "Error occurred during execution of '{0}' process. Execution will be retried (attempt {1} of {2}) in {3} seconds.", _innerProcess, i + 1, MaxRetryAttempts, nextTry), ex); context.Wait(nextTry); if (context.IsShutdownRequested) { break; } } } }
public void Execute(BackgroundProcessContext context) { for (var i = 0; i <= MaxRetryAttempts; i++) { try { _innerProcess.Execute(context); return; } catch (Exception ex) { if (ex is OperationCanceledException && context.IsShutdownRequested) { throw; } // Break the loop after the retry attempts number exceeded. if (i >= MaxRetryAttempts - 1) { throw; } var nextTry = DelayCallback(i); var logLevel = GetLogLevel(i); _logger.Log( logLevel, // ReSharper disable once AccessToModifiedClosure () => $"Error occurred during execution of '{_innerProcess}' process. Execution will be retried (attempt #{i + 1}) in {nextTry} seconds.", ex); context.Wait(nextTry); if (context.IsShutdownRequested) { break; } } } }
public void Execute(BackgroundProcessContext context) { for (var i = 0; i <= MaxRetryAttempts; i++) { try { _innerProcess.Execute(context); return; } catch (Exception ex) { if (ex is OperationCanceledException && context.IsShutdownRequested) { throw; } // Break the loop after the retry attempts number exceeded. if (i >= MaxRetryAttempts - 1) throw; var nextTry = DelayCallback(i); var logLevel = GetLogLevel(i); _logger.Log( logLevel, // ReSharper disable once AccessToModifiedClosure () => $"Error occurred during execution of '{_innerProcess}' process. Execution will be retried (attempt {i + 1} of {MaxRetryAttempts}) in {nextTry} seconds.", ex); context.Wait(nextTry); if (context.IsShutdownRequested) { break; } } } }
/// <inheritdoc /> public void Execute(BackgroundProcessContext context) { if (context == null) throw new ArgumentNullException("context"); var jobsEnqueued = 0; while (EnqueueNextScheduledJob(context)) { jobsEnqueued++; if (context.IsShutdownRequested) { break; } } if (jobsEnqueued != 0) { Logger.InfoFormat("{0} scheduled job(s) enqueued.", jobsEnqueued); } context.Wait(_pollingDelay); }