public override Task RunAsync(CancellationToken cancellationToken) { return(_next. RunAsync(cancellationToken). ContinueWith( task => RetryAsync(task, _next, cancellationToken, _retryCount, _timeBetweenRetries), cancellationToken). Unwrap()); }
public async Task <List <LogItem> > RunAsync() { Log log; try { log = await _coffeeMakerUtil.RunAsync(); } catch (Exception exception) { throw new Exception("Unable to run process: " + exception.Message); } return(log?.Get()); }
public override Task RunAsync(CancellationToken cancellationToken) { return(_next. RunAsync(cancellationToken). ContinueWith(task => { if (!task.IsFaulted || task.Exception == null) { return; } _logger(task.Exception); throw task.Exception; }, cancellationToken)); }
private static async Task RetryAsync(Task task, ITaskRunner next, CancellationToken cancellationToken, int restCount, TimeSpan timeBetweenRetries) { if (!task.IsFaulted || task.Exception == null) { return; } if (restCount == 0) { throw task.Exception; } await Task.Delay(timeBetweenRetries, cancellationToken); await next. RunAsync(cancellationToken). ContinueWith( _ => RetryAsync(_, next, cancellationToken, restCount - 1, timeBetweenRetries), cancellationToken); }
private void StartNew() { if (ThreadsInUse == 0 && WaitingQueueLength == 0) { m_CrawlCompleteEvent.Set(); return; } if (m_CrawlStopped) { if (ThreadsInUse == 0) { m_CrawlCompleteEvent.Set(); } return; } if (MaximumCrawlTime.HasValue && m_Runtime.Elapsed > MaximumCrawlTime.Value) { m_Logger.Verbose("Maximum crawl time({0}) exceeded, cancelling", MaximumCrawlTime.Value); StopCrawl(); return; } if (MaximumCrawlCount.HasValue && MaximumCrawlCount.Value > 0 && MaximumCrawlCount.Value <= m_CrawlerHistory.VisitedCount) { m_Logger.Verbose("CrawlCount exceeded {0}, cancelling", MaximumCrawlCount.Value); StopCrawl(); return; } if (ThreadsInUse < MaximumThreadCount && WaitingQueueLength > 0) { m_Logger.Verbose("Starting new thread {0}", m_BaseUri); m_TaskRunner.RunAsync(WorkerProc); } }