public async Task <IActionResult> GetJobDefinition(int projectId, int jobId)
        {
            _logger.LogInformation("Getting job definition {jobId} in project {projectId}", jobId, projectId);

            var jobDefinition = await _jobDefinitionService.GetJobDefinitionById(jobId);

            var result = _mapper.Map <JobDefinitionDto>(jobDefinition);

            return(Ok(result));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetJobDefinition(int projectId, int jobId)
        {
            _logger.LogRequest("Getting job definition {jobId} in project {projectId}", jobId, projectId);

            var jobDefinition = await _jobDefinitionService.GetJobDefinitionById(jobId);

            var result = _mapper.Map <JobDefinitionDto>(jobDefinition);

            _logger.LogResponse("Job definition {jobId} in project {projectId} retrieved. Reponse body: {@result}", jobId, projectId, result);

            return(Ok(result));
        }
Ejemplo n.º 3
0
        public async Task <int> AddJobQueue(int projectId, string originUrl, string jobType, int?jobDefinitionId, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();

            var project = await _projectRepository.GetById(projectId, cancellationToken);

            bool projectAllowAddingQueue = project?.Status == ProjectStatusFilterType.Active ||
                                           (project?.Status == ProjectStatusFilterType.Deleting && jobType == JobType.Delete);

            if (project == null || !projectAllowAddingQueue)
            {
                throw new ProjectNotFoundException(projectId);
            }

            var inProgressJobSpec = new JobQueueFilterSpecification(projectId, _inProgressJobStatus);
            var inProgressJob     = await _jobQueueRepository.GetSingleBySpec(inProgressJobSpec, cancellationToken);

            if (inProgressJob != null)
            {
                if (project.Status == ProjectStatusFilterType.Deleting && jobType != JobType.Delete)
                {
                    return(inProgressJob.Id);
                }

                throw new JobQueueInProgressException(projectId);
            }

            JobDefinition jobDefinition = null;

            if (jobDefinitionId.HasValue)
            {
                jobDefinition = await _jobDefinitionService.GetJobDefinitionById(jobDefinitionId.Value, cancellationToken);
                await ValidateJobTasks(jobDefinition, cancellationToken);
            }

            // detemine the jobQueue type if it is not provided by the caller
            if (string.IsNullOrWhiteSpace(jobType))
            {
                jobType = JobType.Create;

                var hasBeenCreatedBefore = (await _jobQueueRepository.CountBySpec(new JobQueueFilterSpecification(projectId, new string[] { JobStatus.Completed }))) > 0;

                if (hasBeenCreatedBefore)
                {
                    jobType = JobType.Update;
                }
            }

            var newJobQueue = new JobQueue
            {
                ProjectId         = projectId,
                Code              = await GetNextJobCode(),
                OriginUrl         = originUrl,
                JobType           = jobType,
                JobDefinitionId   = jobDefinition?.Id,
                JobDefinitionName = jobDefinition?.Name,
                IsDeletion        = jobDefinition?.IsDeletion ?? false,
                Status            = JobStatus.Queued
            };

            return(await _jobQueueRepository.Create(newJobQueue, cancellationToken));
        }