private async Task <bool> TryRunJob(CancellationToken cancellationToken, TimeSpan waitTime) { for (var i = 0; i < _settings.JobThrottleSettings.JobRetrievalAttempts; i++) { var job = await GetReadyJob(); var isJobReady = job != null; if (isJobReady) { _horariumLogger.Debug("Try to Run jobMetadata..."); var jobTask = Task.Run(() => _executorJob.Execute(job), CancellationToken.None); _uncompletedTaskList.Add(jobTask); } if (cancellationToken.IsCancellationRequested) { throw new TaskCanceledException(); } if (isJobReady) { return(true); } if (!waitTime.Equals(TimeSpan.Zero)) { await Task.Delay(waitTime, cancellationToken); } } return(false); }
private async Task StartRunnerInternal(CancellationToken cancellationToken) { while (true) { var job = await GetReadyJob(); if (job != null) { _horariumLogger.Debug("Try to Run jobMetadata..."); var jobTask = Task.Run(() => _executorJob.Execute(job), CancellationToken.None); _uncompletedTaskList.Add(jobTask); } if (cancellationToken.IsCancellationRequested) { throw new TaskCanceledException(); } if (!_settings.IntervalStartJob.Equals(TimeSpan.Zero)) { await Task.Delay(_settings.IntervalStartJob, cancellationToken); } } }