public static async Task RunUntilEmptyAsync(this IQueueJob job, CancellationToken cancellationToken = default(CancellationToken)) { var logger = job.GetLogger(); await job.RunContinuousAsync(cancellationToken : cancellationToken, interval : TimeSpan.FromMilliseconds(1), continuationCallback : async() => { var stats = await job.Queue.GetQueueStatsAsync().AnyContext(); logger.Trace("RunUntilEmpty continuation: queue: {Queued} working={Working}", stats.Queued, stats.Working); return(stats.Queued + stats.Working > 0); }).AnyContext(); }
public static Task RunUntilEmptyAsync <T>(this IQueueJob <T> job, CancellationToken cancellationToken = default) where T : class { var logger = job.GetLogger() ?? NullLogger.Instance; return(job.RunContinuousAsync(cancellationToken: cancellationToken, continuationCallback: async() => { // Allow abandoned items to be added in a background task. Thread.Yield(); var stats = await job.Queue.GetQueueStatsAsync().AnyContext(); if (logger.IsEnabled(LogLevel.Trace)) { logger.LogTrace("RunUntilEmpty continuation: Queued={Queued}, Working={Working}, Abandoned={Abandoned}", stats.Queued, stats.Working, stats.Abandoned); } return stats.Queued + stats.Working > 0; })); }