private async Task CheckAndUpdateProcessingJobsIfRunningLongerThenAverageTime(
            List <OutstandingJobResult> processingJobs,
            List <InProgressJobAverageJobCompletionTime> averageJobCompletionTimes,
            long?dcJobId,
            CancellationToken cancellationToken)
        {
            foreach (var inProgressJob in processingJobs)
            {
                var providerJobTimings = averageJobCompletionTimes.SingleOrDefault(a => a.Ukprn == inProgressJob.Ukprn);

                if (providerJobTimings == null)
                {
                    throw new InvalidOperationException($"Unable to find Average Job Completion Times For {inProgressJob.Ukprn}, Period End Start JobId {dcJobId}");
                }

                if (inProgressJob.JobRunTimeDurationInMillisecond > (providerJobTimings.AverageJobCompletionTime ?? 0))
                {
                    Logger.LogWarning($"File Processing job {inProgressJob.DcJobId} Started at {inProgressJob.StartTime}. " +
                                      $"it has been running for {inProgressJob.JobRunTimeDurationInMillisecond} Millisecond which is longer then its average duration of {providerJobTimings.AverageJobCompletionTime} Millisecond, " +
                                      $"now updating job status to TimedOut, Period End Start JobId {dcJobId}");

                    await context.SaveJobStatus(inProgressJob.DcJobId.Value, JobStatus.TimedOut, DateTimeOffset.UtcNow, cancellationToken);
                }
                else
                {
                    Logger.LogDebug($"File Processing job {inProgressJob.DcJobId} Started at {inProgressJob.StartTime}. " +
                                    $"it has been running for {inProgressJob.JobRunTimeDurationInMillisecond} Millisecond which is still with in its average duration of {providerJobTimings.AverageJobCompletionTime} Millisecond, " +
                                    $"Period End Start JobId {dcJobId}");
                }
            }
        }
Example #2
0
        public async Task SaveJobStatus(long jobId, JobStatus jobStatus, DateTimeOffset endTime, CancellationToken cancellationToken)
        {
            var job = await GetJob(jobId, cancellationToken).ConfigureAwait(false);

            if (job == null)
            {
                throw new InvalidOperationException($"Job not stored in the cache. Job: {jobId}");
            }
            job.Status  = jobStatus;
            job.EndTime = endTime;
            var collection = await GetJobCollection().ConfigureAwait(false);

            await collection.AddOrUpdateAsync(reliableTransactionProvider.Current, jobId, job, (key, value) => job,
                                              TransactionTimeout, cancellationToken)
            .ConfigureAwait(false);

            await dataContext.SaveJobStatus(jobId, jobStatus, endTime, cancellationToken).ConfigureAwait(false);
        }