示例#1
0
        public override async Task Process(Message message)
        {
            Guard.ArgumentNotNull(message, nameof(message));

            string specificationId            = message.GetUserProperty <string>(SpecificationIdKey);
            string fundingStreamId            = message.GetUserProperty <string>(FundingStreamIdKey);
            string providerSnapshotIdValue    = message.GetUserProperty <string>(ProviderSnapshotIdKey);
            string disableQueueCalculationJob = message.GetUserProperty <string>(DisableQueueCalculationJobKey);

            Reference user          = message.GetUserDetails();
            string    correlationId = message.GetCorrelationId();

            if (string.IsNullOrWhiteSpace(providerSnapshotIdValue) || !int.TryParse(providerSnapshotIdValue, out int providerSnapshotId))
            {
                throw new NonRetriableException("Invalid provider snapshot id");
            }

            ProviderSnapshot providerSnapshot = await GetProviderSnapshot(fundingStreamId, providerSnapshotId);

            string providerVersionId       = $"{fundingStreamId}-{providerSnapshot.TargetDate:yyyy}-{providerSnapshot.TargetDate:MM}-{providerSnapshot.TargetDate:dd}-{providerSnapshotId}";
            bool   isProviderVersionExists = await _providerVersionService.Exists(providerVersionId);

            if (!isProviderVersionExists)
            {
                IEnumerable <Common.ApiClient.FundingDataZone.Models.Provider> fdzProviders = await GetProvidersInSnapshot(providerSnapshotId);

                ProviderVersionViewModel providerVersionViewModel = CreateProviderVersionViewModel(fundingStreamId, providerVersionId, providerSnapshot, fdzProviders);
                (bool success, IActionResult actionResult) = await _providerVersionService.UploadProviderVersion(providerVersionId, providerVersionViewModel);

                if (!success)
                {
                    string errorMessage = $"Failed to upload provider version {providerVersionId}. {GetErrorMessage(actionResult, providerVersionId)}";

                    _logger.Error(errorMessage);

                    throw new Exception(errorMessage);
                }
            }

            HttpStatusCode httpStatusCode = await _specificationsApiClientPolicy.ExecuteAsync(() => _specificationsApiClient.SetProviderVersion(specificationId, providerVersionId));

            if (!httpStatusCode.IsSuccess())
            {
                string errorMessage = $"Unable to update the specification - {specificationId}, with provider version id  - {providerVersionId}. HttpStatusCode - {httpStatusCode}";

                _logger.Error(errorMessage);

                throw new Exception(errorMessage);
            }

            JobCreateModel mapFdzDatasetsJobCreateModel = new JobCreateModel
            {
                Trigger = new Trigger
                {
                    EntityId   = specificationId,
                    EntityType = "Specification",
                    Message    = "Map datasets for all relationships in specification"
                },
                InvokerUserId          = user.Id,
                InvokerUserDisplayName = user.Name,
                JobDefinitionId        = JobConstants.DefinitionNames.MapFdzDatasetsJob,
                ParentJobId            = null,
                SpecificationId        = specificationId,
                CorrelationId          = correlationId,
                Properties             = new Dictionary <string, string>
                {
                    { "specification-id", specificationId },
                    { "disableQueueCalculationJob", disableQueueCalculationJob },
                }
            };

            try
            {
                await _jobManagement.QueueJob(mapFdzDatasetsJobCreateModel);
            }
            catch (Exception ex)
            {
                string errorMessage = $"Failed to queue MapFdzDatasetsJob for specification - {specificationId}";
                _logger.Error(ex, errorMessage);
                throw;
            }
        }