Beispiel #1
0
        /// <summary>
        /// Use Initialize for initializing progress for specified projection
        /// </summary>
        /// <param name="version">Projection version that should be initialized</param>
        public async Task InitializeAsync(ProjectionVersion version)
        {
            ProjectionName = version.ProjectionName;
            IEnumerable <Type> projectionHandledEventTypes = projectionVersionHelper.GetInvolvedEventTypes(ProjectionName.GetTypeByContract());

            foreach (var eventType in projectionHandledEventTypes)
            {
                TotalEvents += (ulong)await messageCounter.GetCountAsync(eventType).ConfigureAwait(false);
            }

            Processed = 0;
        }
Beispiel #2
0
        protected override async Task <JobExecutionStatus> RunJobAsync(IClusterOperations cluster, CancellationToken cancellationToken = default)
        {
            ProjectionVersion version = Data.Version;
            Type projectionType       = version.ProjectionName.GetTypeByContract();

            await progressTracker.InitializeAsync(version).ConfigureAwait(false);

            if (await projectionVersionHelper.ShouldBeRetriedAsync(version).ConfigureAwait(false))
            {
                return(JobExecutionStatus.Running);
            }

            if (await projectionVersionHelper.ShouldBeCanceledAsync(version, Data.DueDate).ConfigureAwait(false))
            {
                if (Data.IsCanceled == false)
                {
                    await CancelJobAsync(cluster).ConfigureAwait(false);
                }

                logger.Info(() => $"The job {version} has been cancelled.");
                return(JobExecutionStatus.Canceled);
            }

            await projectionStoreInitializer.InitializeAsync(version).ConfigureAwait(false);

            var startSignal = progressTracker.GetProgressStartedSignal();

            signalPublisher.Publish(startSignal);

            IEnumerable <Type> projectionHandledEventTypes = projectionVersionHelper.GetInvolvedEventTypes(projectionType);

            foreach (Type eventType in projectionHandledEventTypes)
            {
                string eventTypeId = eventType.GetContractId();

                bool hasMoreRecords = true;
                while (hasMoreRecords && Data.IsCompleted == false)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        logger.Info(() => $"The job {version} has been cancelled.");
                        return(JobExecutionStatus.Running);
                    }

                    if (Data.IsCanceled || await projectionVersionHelper.ShouldBeCanceledAsync(version, Data.DueDate).ConfigureAwait(false))
                    {
                        if (Data.IsCanceled == false)
                        {
                            await CancelJobAsync(cluster).ConfigureAwait(false);
                        }

                        logger.Info(() => $"The job {version} has been cancelled.");
                        return(JobExecutionStatus.Canceled);
                    }

                    hasMoreRecords = await RebuildEventsAsync(eventTypeId, cluster, cancellationToken).ConfigureAwait(false);
                }
            }

            Data.IsCompleted = true;
            Data.Timestamp   = DateTimeOffset.UtcNow;
            Data             = await cluster.PingAsync(Data).ConfigureAwait(false);

            var finishSignal = progressTracker.GetProgressFinishedSignal();

            signalPublisher.Publish(finishSignal);

            logger.Info(() => $"The job has been completed.");
            return(JobExecutionStatus.Completed);
        }