public async Task <IActionResult> UpdateJobTaskOrder(int projectId, int jobId, UpdateTaskOrderDto dto)
        {
            _logger.LogInformation("Updating tasks order for job {jobId} in project {projectId}. Request body: {@dto}", jobId, projectId, dto);

            var jobs = await _jobDefinitionService.GetJobTaskDefinitions(jobId);

            foreach (var jobOrder in dto.TaskOrders)
            {
                var job = jobs.FirstOrDefault(j => j.Id == jobOrder.Key);
                job.Sequence = jobOrder.Value;
                await _jobDefinitionService.UpdateJobTaskDefinition(job);
            }

            return(Ok());
        }
        public async Task <IActionResult> UpdateJobTaskOrder(int projectId, int jobId, UpdateTaskOrderDto dto)
        {
            _logger.LogRequest("Updating tasks order for job {jobId} in project {projectId}. Request body: {@dto}", jobId, projectId, dto);

            var tasks = await _jobDefinitionService.GetJobTaskDefinitions(jobId, decrypt : true);

            foreach (var taskOrder in dto.TaskOrders)
            {
                var task = tasks.FirstOrDefault(j => j.Id == taskOrder.Key);
                task.Sequence = taskOrder.Value;
                await _jobDefinitionService.UpdateJobTaskDefinition(task, validate : false);
            }

            _logger.LogResponse("Task order for job definition {jobId} in project {projectId} updated", jobId, projectId);

            return(Ok());
        }
Пример #3
0
        public async Task ExecuteJob(JobDto jobQueue)
        {
            using (_logger.BeginScope(new JobScope(jobQueue.ProjectId, jobQueue.Id)))
            {
                try
                {
                    _logger.LogInformation($"Executing job queue {jobQueue.Code}.");

                    var jobTasks = await _jobDefinitionService.GetJobTaskDefinitions(jobQueue.ProjectId, jobQueue.JobDefinitionId ?? 0);

                    var workingLocation = Path.Combine(_engineConfig.WorkingLocation, jobQueue.Code);
                    var result          = await _taskRunner.Run(jobQueue.ProjectId, jobQueue, jobTasks, _engineConfig.TaskProvidersLocation, workingLocation);

                    if (result.Values.Any(t => t.IsSuccess && t.StopTheProcess))
                    {
                        jobQueue.Status = JobStatus.Pending;
                    }
                    else if (result.Values.Any(t => !t.IsSuccess))
                    {
                        jobQueue.Status = JobStatus.Error;
                    }
                    else
                    {
                        jobQueue.Status = JobStatus.Completed;
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, ex.Message);
                    jobQueue.Status = JobStatus.Error;
                }

                await _jobQueueService.UpdateJobQueue(jobQueue.Id, new UpdateJobDto
                {
                    Id = jobQueue.Id,
                    CatapultEngineId          = jobQueue.CatapultEngineId,
                    CatapultEngineIPAddress   = jobQueue.CatapultEngineIPAddress,
                    CatapultEngineMachineName = jobQueue.CatapultEngineMachineName,
                    CatapultEngineVersion     = jobQueue.CatapultEngineVersion,
                    JobType        = jobQueue.JobType,
                    Status         = jobQueue.Status,
                    JobTasksStatus = jobQueue.JobTasksStatus,
                    OutputValues   = jobQueue.OutputValues
                });

                await _jobLogWriter.EndJobLog(jobQueue.Id);

                await _jobQueueService.SendNotification(jobQueue.Id);

                if (jobQueue.Status == JobStatus.Completed &&
                    jobQueue.IsDeletion &&
                    jobQueue.ProjectStatus == ProjectStatusFilterType.Deleting)
                {
                    _logger.LogInformation($"Deleting project {jobQueue.ProjectId}");
                    await _projectService.DeleteProjectByEngine(jobQueue.ProjectId);
                }
            }
        }
Пример #4
0
        public async Task <IActionResult> GetJobTaskDefinitions(int jobId)
        {
            _logger.LogInformation("Getting job task definitions in job {jobId}", jobId);

            var jobTaskDefinitions = await _jobDefinitionService.GetJobTaskDefinitions(jobId);

            var results = _mapper.Map <List <JobTaskDefinitionDto> >(jobTaskDefinitions);

            return(Ok(results));
        }
Пример #5
0
        private async Task ValidateJobTasks(JobDefinition jobDefinition, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var tasks = await _jobDefinitionService.GetJobTaskDefinitions(jobDefinition.Id, cancellationToken : cancellationToken);

                foreach (var task in tasks)
                {
                    await _jobDefinitionService.ValidateJobTaskDefinition(jobDefinition, task, cancellationToken : cancellationToken);
                }
            }
            catch (Exception ex)
            {
                throw new TaskValidationException(jobDefinition.Name, ex.Message, ex);
            }
        }
Пример #6
0
        public override string Execute()
        {
            Console.WriteLine($"Trying to get tasks for job definition {Job}...");

            string message;

            var project = _projectService.GetProjectByName(Project).Result;

            if (project != null)
            {
                var job = _jobDefinitionService.GetJobDefinitionByName(project.Id, Job).Result;

                if (job != null)
                {
                    var tasks = _jobDefinitionService.GetJobTaskDefinitions(project.Id, job.Id).Result;

                    var secretConfig = new List <string>();
                    foreach (var task in tasks)
                    {
                        var configs = _pluginService.GetProviderAdditionalConfigByProviderName(task.Provider).Result;
                        secretConfig.AddRange(configs.Where(c => c.IsSecret).Select(c => c.Name));
                    }

                    message = tasks.ToListCliString($"Found {tasks.Count} task(s):", secretConfig.ToArray(), excludedFields: new string[]
                    {
                        "JobDefinitionId",
                        "Configs",
                        "AdditionalConfigs"
                    });
                    return(message);
                }
            }

            message = $"Failed to fetch tasks. Make sure the project and job names are correct.";

            return(message);
        }