public async Task UpdateJob_Fail_InvalidJobId() { IContainer container = Registrations(); using (var scope = container.BeginLifetimeScope()) { // Create the schema in the database var options = scope.Resolve <DbContextOptions <JobQueueDataContext> >(); using (var context = new JobQueueDataContext(options)) { context.Database.EnsureCreated(); } IFileUploadJobManager manager = scope.Resolve <IFileUploadJobManager>(); await Assert.ThrowsAsync <ArgumentException>(() => manager.UpdateJobStage(100, false)); } }
public ActionResult Post([FromBody] JobStatusDto jobStatusDto) { if (jobStatusDto == null) { _logger.LogError($"Job Post request received with empty data for JobStatusDto"); return(BadRequest()); } _logger.LogInfo("Post for job received for job: {@jobStatusDto} ", new[] { jobStatusDto }); if (jobStatusDto.JobId == 0) { _logger.LogWarning("Job Post request received with empty data"); return(BadRequest()); } if (!Enum.IsDefined(typeof(JobStatusType), jobStatusDto.JobStatus)) { _logger.LogWarning($"Job Post request received with bad status {jobStatusDto.JobStatus}"); return(BadRequest("Status is not a valid value")); } try { var job = _jobManager.GetJobById(jobStatusDto.JobId); if (job == null) { _logger.LogError($"JobId {jobStatusDto.JobId} is not valid for job status update"); return(BadRequest("Invalid job Id")); } FileUploadJob metaData = _fileUploadJobManager.GetJobById(jobStatusDto.JobId); // If we are changing from Waiting to Ready, it means processing should go to second stage if (job.Status == JobStatusType.Waiting && (JobStatusType)jobStatusDto.JobStatus == JobStatusType.Ready) { _fileUploadJobManager.UpdateJobStage(job.JobId, !metaData.IsFirstStage); } bool result = _jobManager.UpdateJobStatus(job.JobId, (JobStatusType)jobStatusDto.JobStatus); if (result) { _logger.LogInfo($"Successfully updated job status for job Id: {jobStatusDto.JobId}"); // Todo: Remove this block of code at some point, it's to make cross loading work when we send a message, but we won't receive a response from the other system. if (job.CrossLoadingStatus == null) { return(Ok()); } if ((JobStatusType)jobStatusDto.JobStatus != JobStatusType.Completed) { return(Ok()); } if (metaData.IsFirstStage) { return(Ok()); } result = _jobManager.UpdateCrossLoadingStatus(job.JobId, JobStatusType.Completed); if (result) { _logger.LogInfo($"Successfully updated cross loading job status for job Id: {jobStatusDto.JobId}"); return(Ok()); } _logger.LogWarning($"Update cross loading status failed for job Id: {jobStatusDto.JobId}"); return(BadRequest()); } _logger.LogWarning($"Update status failed for job Id: {jobStatusDto.JobId}"); return(BadRequest()); } catch (Exception ex) { _logger.LogError("Post for job failed for job: {@jobStatusDto}", ex, new[] { jobStatusDto }); return(BadRequest()); } }