public async Task ProcessDeadLetteredMessage_GivenMessageAndLogIsUpdated_LogsInformation()
        {
            // Arrange
            const string jobId = "job-id-1";

            JobLog jobLog = new JobLog
            {
                Id = "job-log-id-1"
            };

            Message message = new Message();

            message.UserProperties.Add("jobId", jobId);

            IJobManagement jobManagement = CreateJobManagement();

            jobManagement
            .AddJobLog(Arg.Is(jobId), Arg.Any <JobLogUpdateModel>())
            .Returns(jobLog);

            ILogger logger = CreateLogger();

            IDeadletterService service = CreateJobHelperService(jobManagement, logger);

            // Act
            await service.Process(message);

            // Assert
            logger
            .Received(1)
            .Information(Arg.Is($"A new job log was added to inform of a dead lettered message with job log id '{jobLog.Id}' on job with id '{jobId}'"));
        }
        public async Task Process(Message message)
        {
            Guard.ArgumentNotNull(message, nameof(message));

            if (!message.UserProperties.ContainsKey("jobId"))
            {
                _logger.Error("Missing job id from dead lettered message");
                return;
            }

            string jobId = message.UserProperties["jobId"].ToString();

            Common.ApiClient.Jobs.Models.JobLogUpdateModel jobLogUpdateModel = new Common.ApiClient.Jobs.Models.JobLogUpdateModel
            {
                CompletedSuccessfully = false,
                Outcome = $"The job has exceeded its maximum retry count and failed to complete successfully"
            };

            try
            {
                Common.ApiClient.Jobs.Models.JobLog jobLog = await _jobManagement.AddJobLog(jobId, jobLogUpdateModel);

                if (jobLog == null)
                {
                    _logger.Error($"Failed to add a job log for job id '{jobId}'");
                }
                else
                {
                    _logger.Information($"A new job log was added to inform of a dead lettered message with job log id '{jobLog.Id}' on job with id '{jobId}'");
                }
            }
            catch (Exception exception)
            {
                _logger.Error(exception, $"Failed to add a job log for job id '{jobId}'");
            }
        }
Exemple #3
0
 public async Task NotifyProgress(int itemCount) => await _jobManagement.AddJobLog(Job.Id, new JobLogUpdateModel { ItemsProcessed = itemCount });
Exemple #4
0
 private async Task AddJobTracking(string jobId, JobLogUpdateModel tracking)
 {
     await _jobManagement.AddJobLog(jobId, tracking);
 }
 private async Task AddJobLog(JobLogUpdateModel jobLog, string jobId)
 {
     await _jobs.AddJobLog(jobId, jobLog);
 }