コード例 #1
0
        public void CanGetS3KeyForExport()
        {
            return;

            var jobId       = "Some id";
            var filename    = "dummy";
            var key         = ExportJob.GetS3Key(jobId, filename);
            var expectedKey = $"3dpm/{jobId}/{filename}";

            Assert.AreEqual(expectedKey, key, "Wrong S3 key");
        }
コード例 #2
0
        public JobStatusResult GetJobStatus(string jobId)
        {
            log.LogInformation($"GetJobStatus: jobId={jobId}");

            var jobData = JobStorage.Current.GetConnection()?.GetJobData(jobId);
            var status  = jobData?.State;

            if (string.IsNullOrEmpty(status))
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError,
                                                                       $"Missing job details for {jobId}"));
            }

            log.LogInformation($"GetJobStatus: {jobId} status={status}");
            string         key          = null;
            string         downloadLink = null;
            FailureDetails details      = null;

            if (status.Equals(Hangfire.States.SucceededState.StateName, StringComparison.OrdinalIgnoreCase))
            {
                if (Request.Path.Value.Contains("export"))
                {
                    // Attempt to get the download link that should have been set in the job
                    key          = JobStorage.Current.GetConnection().GetJobParameter(jobId, ExportJob.S3_KEY_STATE_KEY);
                    downloadLink = JobStorage.Current.GetConnection().GetJobParameter(jobId, ExportJob.DOWNLOAD_LINK_STATE_KEY);
                    log.LogInformation($"Getting export job {jobId} downloadLink={downloadLink}");

                    if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(downloadLink))
                    {
                        log.LogWarning("S3Key or Downloadlink not set in background job, attempting to find it via the original request");
                        var filename = (jobData?.Job.Args[0] as ScheduleJobRequest).Filename ?? jobId;
                        key          = ExportJob.GetS3Key(jobId, filename);
                        downloadLink = exportJob.GetDownloadLink(jobId, filename);
                    }
                }
            }
            else if (status.Equals(Hangfire.States.DeletedState.StateName, StringComparison.OrdinalIgnoreCase))
            {
                var detailsJson = JobStorage.Current.GetConnection().GetJobParameter(jobId, ExportFailedState.EXPORT_DETAILS_KEY);
                log.LogDebug($"GetJobStatus: detailsJson={detailsJson}");
                if (!string.IsNullOrEmpty(detailsJson))
                {
                    details = JsonConvert.DeserializeObject <FailureDetails>(detailsJson);
                }
            }

            // Change behavior so it's not a breaking change for the UI.

            if (details != null &&
                status.Equals(Hangfire.States.DeletedState.StateName, StringComparison.OrdinalIgnoreCase) &&
                details.Result.Code != ContractExecutionStatesEnum.ExecutedSuccessfully)
            {
                status = Hangfire.States.FailedState.StateName;
            }

            var result = new JobStatusResult {
                Key = key, Status = status, DownloadLink = downloadLink, FailureDetails = details
            };

            log.LogInformation($"GetJobStatus: result={JsonConvert.SerializeObject(result)}");
            return(result);
        }