コード例 #1
0
ファイル: JobRepository.cs プロジェクト: KarolisBreidokas/BVS
        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);
        }
コード例 #2
0
        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));
            }
        }
コード例 #3
0
        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));
            }
        }
コード例 #4
0
        public async Task <JobDto> CreateJobQueue(int projectId, NewJobDto newJobQueue)
        {
            var path = $"project/{projectId}/queue";

            return(await Api.Post <NewJobDto, JobDto>(path, newJobQueue));
        }