public async Task <int> CreateJob(NewJobDto message) { var jobEntity = new Job { Description = message.Description, State = message.State, MessageId = message.MessageId }; _jobs.Add(jobEntity); await _context.SaveChangesAsync(); return(jobEntity.Id); }
public async Task <IActionResult> CreateDefaultJobQueue(int projectId, NewJobDto newJobQueue) { _logger.LogRequest("Creating default job queue for project {projectId}. Request body: {@newJobQueue}", projectId, newJobQueue); try { if (projectId != newJobQueue.ProjectId) { _logger.LogWarning("Project Id doesn't match"); return(BadRequest("Project Id doesn't match.")); } var queueId = await _jobQueueService.AddDefaultJobQueue(newJobQueue.ProjectId, newJobQueue.OriginUrl, newJobQueue.JobType); var job = await _jobQueueService.GetJobQueueById(projectId, queueId); var result = _mapper.Map <JobDto>(job); _logger.LogResponse("Default job queue in project {projectId} created. Response body: {@result}", projectId, result); return(CreatedAtRoute("GetJobQueueById", new { projectId = newJobQueue.ProjectId, queueId }, result)); } catch (JobQueueInProgressException jobEx) { _logger.LogWarning(jobEx, "Job queue in progress"); return(BadRequest(jobEx.Message)); } catch (ProjectNotFoundException projEx) { _logger.LogWarning(projEx, "Project not found"); return(BadRequest(projEx.Message)); } catch (TaskValidationException taskEx) { _logger.LogWarning(taskEx, "Task validation failed"); return(BadRequest(taskEx.Message)); } catch (DefaultJobDefinitionNotFoundException jobEx) { _logger.LogWarning(jobEx, "Default job definition not found"); return(BadRequest(jobEx.Message)); } }
public async Task <IActionResult> CreateJobQueue(int projectId, NewJobDto newJobQueue) { _logger.LogInformation("Creating job queue for project {projectId}. Request body: {@newJobQueue}", projectId, newJobQueue); try { if (projectId != newJobQueue.ProjectId) { _logger.LogWarning("Project Id doesn't match"); return(BadRequest("Project Id doesn't match.")); } var queueId = await _jobQueueService.AddJobQueue(newJobQueue.ProjectId, newJobQueue.OriginUrl, newJobQueue.JobType, newJobQueue.JobDefinitionId); var job = await _jobQueueService.GetJobQueueById(projectId, queueId); var result = _mapper.Map <JobDto>(job); return(CreatedAtRoute("GetJobQueueById", new { projectId = newJobQueue.ProjectId, queueId }, result)); } catch (JobQueueInProgressException jobEx) { _logger.LogWarning(jobEx, "Job queue in progress"); return(BadRequest(jobEx.Message)); } catch (ProjectNotFoundException projEx) { _logger.LogWarning(projEx, "Project not found"); return(BadRequest(projEx.Message)); } }
public async Task <JobDto> CreateJobQueue(int projectId, NewJobDto newJobQueue) { var path = $"project/{projectId}/queue"; return(await Api.Post <NewJobDto, JobDto>(path, newJobQueue)); }