コード例 #1
0
        public async Task <PublishResult> PublishCourseUploadForProvider(Guid providerId, UserInfo publishedBy)
        {
            using (var dispatcher = _sqlQueryDispatcherFactory.CreateDispatcher(System.Data.IsolationLevel.ReadCommitted))
            {
                await AcquireExclusiveCourseUploadLockForProvider(providerId, dispatcher);

                var courseUpload = await dispatcher.ExecuteQuery(new GetLatestUnpublishedCourseUploadForProvider()
                {
                    ProviderId = providerId
                });

                if (courseUpload == null)
                {
                    throw new InvalidStateException(InvalidStateReason.NoUnpublishedCourseUpload);
                }

                if (courseUpload.UploadStatus.IsUnprocessed())
                {
                    throw new InvalidUploadStatusException(
                              courseUpload.UploadStatus,
                              UploadStatus.ProcessedWithErrors,
                              UploadStatus.ProcessedSuccessfully);
                }

                if (courseUpload.UploadStatus == UploadStatus.ProcessedWithErrors)
                {
                    return(PublishResult.UploadHasErrors());
                }

                var uploadStatus = await RevalidateCourseUploadIfRequired(dispatcher, courseUpload.CourseUploadId);

                if (uploadStatus == UploadStatus.ProcessedWithErrors)
                {
                    return(PublishResult.UploadHasErrors());
                }

                var publishedOn = _clock.UtcNow;

                var publishResult = await dispatcher.ExecuteQuery(new PublishCourseUpload()
                {
                    CourseUploadId = courseUpload.CourseUploadId,
                    PublishedBy    = publishedBy,
                    PublishedOn    = publishedOn
                });

                await dispatcher.Commit();

                Debug.Assert(publishResult.IsT1);
                var publishedCourseRunIds = publishResult.AsT1.PublishedCourseRunIds;

                // Update the FAC index - we do this in a separate transaction in the background since it can cause timeouts
                // when done inside the PublishCourseUpload handler.
                // A mop-up job inside the Functions project ensures that any updates that fail here get captured eventually.
                await _backgroundWorkScheduler.Schedule(UpdateFindACourseIndex, state : publishedCourseRunIds);

                return(PublishResult.Success(publishedCourseRunIds.Count));
            }
コード例 #2
0
        public async Task <PublishResult> PublishApprenticeshipUploadForProvider(Guid providerId, UserInfo publishedBy)
        {
            using (var dispatcher = _sqlQueryDispatcherFactory.CreateDispatcher(System.Data.IsolationLevel.ReadCommitted))
            {
                await AcquireExclusiveApprenticeshipUploadLockForProvider(providerId, dispatcher);

                var apprenticeshipUpload = await dispatcher.ExecuteQuery(new GetLatestUnpublishedApprenticeshipUploadForProvider()
                {
                    ProviderId = providerId
                });

                if (apprenticeshipUpload == null)
                {
                    throw new InvalidStateException(InvalidStateReason.NoUnpublishedApprenticeshipUpload);
                }

                if (apprenticeshipUpload.UploadStatus.IsUnprocessed())
                {
                    throw new InvalidUploadStatusException(
                              apprenticeshipUpload.UploadStatus,
                              UploadStatus.ProcessedWithErrors,
                              UploadStatus.ProcessedSuccessfully);
                }

                if (apprenticeshipUpload.UploadStatus == UploadStatus.ProcessedWithErrors)
                {
                    return(PublishResult.UploadHasErrors());
                }

                var uploadStatus = await RevalidateApprenticeshipUploadIfRequired(dispatcher, apprenticeshipUpload.ApprenticeshipUploadId);

                if (uploadStatus == UploadStatus.ProcessedWithErrors)
                {
                    return(PublishResult.UploadHasErrors());
                }

                var publishedOn = _clock.UtcNow;

                var publishResult = await dispatcher.ExecuteQuery(new PublishApprenticeshipUpload()
                {
                    ApprenticeshipUploadId = apprenticeshipUpload.ApprenticeshipUploadId,
                    PublishedBy            = publishedBy,
                    PublishedOn            = publishedOn
                });

                await dispatcher.Commit();

                Debug.Assert(publishResult.IsT1);
                var publishedApprenticeshipsCount = publishResult.AsT1.PublishedApprenticeshipsCount;

                return(PublishResult.Success(publishedApprenticeshipsCount));
            }
        }