Beispiel #1
0
        private async Task CheckForCancelledJobsAsync(IEnumerable <ImportManagerQueueRecord> managerJobs)
        {
            if (managerJobs != null && managerJobs.Any())
            {
                var cancelledJobs = managerJobs.Where(x => x.QueueStatus == Constant.Status.Queue.CANCELLATION_REQUESTED);
                if (cancelledJobs.Any())
                {
                    foreach (var job in cancelledJobs)
                    {
                        SetJobProperties(job);
                        IEnumerable <ImportJobError> jobErrors = await _artifactQueryHelper.GetImportJobErrorsAsync(_apiOptions, job.WorkspaceArtifactId, _rsapiRepositoryGroup.RdoRepository, job.JobId);

                        Int32 numberOfWorkerRecords = await SqlQueryHelper.CountImportWorkerRecordsAsync(AgentHelper.GetDBContext(-1), job.WorkspaceArtifactId, job.JobId);
                        await UpdateJobStatisticsAsync(job, jobErrors, numberOfWorkerRecords);
                        await UpdateJobStatusAsync(job.WorkspaceArtifactId, job.JobId, Constant.Status.Job.CANCELLED);
                        await ClearQueueRecords(job.WorkspaceArtifactId, job.JobId);
                        await SendEmail(job, Constant.Status.Job.CANCELLED);
                    }
                }
            }
        }
        public override Response Execute()
        {
            Response response = new Response()
            {
                Success = true,
                Message = string.Empty
            };

            if (!ActiveArtifact.IsNew)
            {
                var statusField   = ActiveArtifact.Fields[Constant.Guids.Field.ImportUtilityJob.Status.ToString()].Value;
                var expectedField = ActiveArtifact.Fields[Constant.Guids.Field.ImportUtilityJob.Expected.ToString()].Value;
                var submittedForMigrationField = ActiveArtifact.Fields[Constant.Guids.Field.ImportUtilityJob.SubmittedForMigration.ToString()].Value;
                if (statusField != null && statusField.Value != null & expectedField != null && submittedForMigrationField != null && submittedForMigrationField.Value != null)
                {
                    String  currentStatus           = (String)statusField.Value;
                    Int32   expectedNumberOfImports = ((Int32?)expectedField.Value).GetValueOrDefault();
                    Boolean submittedForMigration   = ((Boolean?)submittedForMigrationField.Value).GetValueOrDefault();

                    if (currentStatus == Constant.Status.Job.IN_PROGRESS_WORKER && submittedForMigration && expectedNumberOfImports > 0)
                    {
                        using (var proxy = Helper.GetServicesManager().CreateProxy <IRSAPIClient>(ExecutionIdentity.System))
                        {
                            var apiOptions = new APIOptions();
                            proxy.APIOptions = apiOptions;
                            ISqlQueryHelper              sqlQueryHelper        = new SqlQueryHelper();
                            IArtifactQueries             artifactQueries       = new ArtifactQueries();
                            Int32                        numberOfWorkerRecords = sqlQueryHelper.CountImportWorkerRecordsAsync(Helper.GetDBContext(-1), Helper.GetActiveCaseID(), ActiveArtifact.ArtifactID).Result;
                            IEnumerable <ImportJobError> jobErrors             = artifactQueries.GetImportJobErrorsAsync(apiOptions, Helper.GetActiveCaseID(), proxy.Repositories.RDO, ActiveArtifact.ArtifactID).Result;
                            ActiveArtifact.Fields[Constant.Guids.Field.ImportUtilityJob.Imported.ToString()].Value.Value    = Utility.CalculateImportJobImports(jobErrors, expectedNumberOfImports, numberOfWorkerRecords);
                            ActiveArtifact.Fields[Constant.Guids.Field.ImportUtilityJob.NotImported.ToString()].Value.Value = Utility.CalculateImportJobObjectsThatWereNotImported(jobErrors, expectedNumberOfImports, numberOfWorkerRecords);
                        }
                    }
                }
            }

            return(response);
        }
Beispiel #3
0
        private async Task CheckForCompletedJobsAsync(IEnumerable <ImportManagerQueueRecord> managerJobs)
        {
            if (managerJobs != null && managerJobs.Any())
            {
                var jobsInProgress = managerJobs.Where(x => x.QueueStatus == Constant.Status.Queue.WAITING_FOR_WORKERS_TO_FINISH);
                if (jobsInProgress.Any())
                {
                    foreach (var job in jobsInProgress)
                    {
                        SetJobProperties(job);
                        Int32 numberOfWorkerRecords = await SqlQueryHelper.CountImportWorkerRecordsAsync(AgentHelper.GetDBContext(-1), job.WorkspaceArtifactId, job.JobId);

                        if (numberOfWorkerRecords == 0)
                        {
                            IEnumerable <ImportJobError> jobErrors = await _artifactQueryHelper.GetImportJobErrorsAsync(_apiOptions, job.WorkspaceArtifactId, _rsapiRepositoryGroup.RdoRepository, job.JobId);

                            // Job Statistics should only be updated when they job type is validate & submit
                            if (job.JobType == Constant.ImportUtilityJob.JobType.VALIDATE_SUBMIT)
                            {
                                await UpdateJobStatisticsAsync(job, jobErrors, numberOfWorkerRecords);
                            }
                            if (jobErrors.Any())
                            {
                                await UpdateJobStatusAsync(job.WorkspaceArtifactId, job.JobId, Constant.Status.Job.COMPLETED_WITH_ERRORS);
                                await SendEmail(job, Constant.Status.Job.COMPLETED_WITH_ERRORS);
                            }
                            else
                            {
                                await UpdateJobStatusAsync(job.WorkspaceArtifactId, job.JobId, Constant.Status.Job.COMPLETED);
                                await SendEmail(job, Constant.Status.Job.COMPLETED);
                            }
                            await ClearQueueRecords(job.WorkspaceArtifactId, job.JobId);
                        }
                    }
                }
            }
        }