Ejemplo n.º 1
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);
                }
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> SendNotification(int queueId)
        {
            _logger.LogRequest("Sending email notification for job queue {queueId}", queueId);

            await _jobQueueService.SendNotification(queueId, _configuration[ConfigurationKey.WebUrl]);

            _logger.LogResponse("Notification for job queue {queueId} sent", queueId);

            return(Ok());
        }