public async Task MoveJobForProcessingAsync(Job job) { if (job == null) { return; } _logger.LogInfo($"Job id: {job.JobId} received for moving to queue", jobIdOverride: job.JobId); var message = await _jobContextMessageFactories[job.JobType].CreateMessageParametersAsync(job.JobId); try { var jobStatusUpdated = await _jobQueueManager.UpdateJobStatus(job.JobId, JobStatusType.MovedForProcessing); _logger.LogInfo($"Job id: {job.JobId} status updated successfully", jobIdOverride: job.JobId); if (jobStatusUpdated) { try { await _messagingService.SendMessageAsync(message); await _auditor.AuditAsync(message.JobContextMessage, AuditEventType.JobSubmitted); } catch (Exception ex) { _logger.LogError($"Job id: {job.JobId} sending to service bus failed", ex, jobIdOverride: job.JobId); await _auditor.AuditAsync( message.JobContextMessage, AuditEventType.ServiceFailed, $"Failed to send message to Service bus queue with exception : {ex}"); await _jobQueueManager.UpdateJobStatus(job.JobId, JobStatusType.Failed); } } else { _logger.LogWarning($"Job id : {job.JobId} failed to send to service bus", jobIdOverride: job.JobId); await _auditor.AuditAsync( message.JobContextMessage, AuditEventType.JobFailed, "Failed to update job status, no message is added to the service bus queue"); } } catch (Exception exception) { _logger.LogError($"Job id: {job.JobId}", exception, jobIdOverride: job.JobId); await _auditor.AuditAsync( message.JobContextMessage, AuditEventType.ServiceFailed, $"Failed to update job status with exception : {exception}"); } }