Example #1
0
        private async Task BackgroundProcessing(CancellationToken cancellationToken)
        {
            Log.Information("Background processing thread is started");

            while (!cancellationToken.IsCancellationRequested)
            {
                var job = jobQueue.Dequeue();
                if (job == null)
                {
                    await Task.Delay(500, cancellationToken);

                    continue;
                }

                var(result, refreshAction) = await job;

                if (hubContext == null)
                {
                    continue;
                }

                await hubContext.Clients.All.SendCoreAsync("jobFinished", new object[] { result }, cancellationToken);

                if (refreshAction != null)
                {
                    await hubContext.Clients.All.SendCoreAsync("refresh", new object[] { refreshAction }, cancellationToken);
                }
            }
        }
Example #2
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            _tokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
            while (cancellationToken.IsCancellationRequested == false)
            {
                try
                {
                    var jobSettings = _queue.Dequeue();
                    if (jobSettings != null)
                    {
                        var jobStatus = (JobStatus)null;
                        do
                        {
                            jobStatus = await _jenkinsService.GetJobStatusAsync(jobSettings.JobPath);

                            if (jobStatus.Building)
                            {
                                await Task.Delay(3000);
                            }
                        } while (jobStatus.Building);
                        await _client.SendTextMessageAsync(jobSettings.ChatId, $"{jobSettings.JobDisplayName} has been finished with status {jobStatus.Status} on {jobStatus.TimeStamp.FromUnixTimeMilliseconds():dd.MM.yyyy HH:mm}");
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e, e.Message);
                }
            }
        }
Example #3
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            _cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
            while (cancellationToken.IsCancellationRequested == false)
            {
                try
                {
                    var nextJob = _queue.Dequeue(cancellationToken);
                    nextJob.SetRunning();
                    await _repository.Update(nextJob, cancellationToken);

                    _logger.LogInformation($"Task {nextJob.Id} run");

                    await Task.Delay(LONG_RUNNING_TIME, cancellationToken);

                    nextJob.SetFinished();
                    await _repository.Update(nextJob, cancellationToken);

                    _logger.LogInformation($"Task {nextJob.Id} was finished");
                }
                catch (OperationCanceledException e)
                {
                    _logger.LogWarning("Operation was cancelled");
                    throw;
                }
            }
        }
 public override IFetchedJob FetchNextJob(string[] queues, CancellationToken cancellationToken)
 {
     if (queues == null || queues.Length == 0)
     {
         throw new ArgumentNullException(nameof(queues));
     }
     return(_queue.Dequeue(queues, cancellationToken));
 }