Exemple #1
0
        public void Handle(RebuildIndexInternal sagaTimeout)
        {
            var job    = jobFactory.CreateJob(sagaTimeout.EventStoreIndexRequest.Timebox);
            var result = jobRunner.ExecuteAsync(job).GetAwaiter().GetResult();

            if (result == JobExecutionStatus.Running)
            {
                RequestTimeout(new RebuildIndexInternal(sagaTimeout.EventStoreIndexRequest, DateTime.UtcNow.AddSeconds(30)));
            }
            else if (result == JobExecutionStatus.Failed)
            {
                // log error
                RequestTimeout(new RebuildIndexInternal(sagaTimeout.EventStoreIndexRequest, DateTime.UtcNow.AddSeconds(30)));
            }
            else if (result == JobExecutionStatus.Completed)
            {
                var finalize = new FinalizeEventStoreIndexRequest(sagaTimeout.EventStoreIndexRequest.Id);
                commandPublisher.Publish(finalize);
            }
        }
        public async Task HandleAsync(RebuildIndexInternal sagaTimeout)
        {
            ICronusJob <object> job = null;
            // we need to redesign the job factories
            var theId = sagaTimeout.EventStoreIndexRequest.Id.Id;

            if (theId.Equals(typeof(EventToAggregateRootId).GetContractId(), StringComparison.OrdinalIgnoreCase))
            {
                job = jobFactory.CreateJob(sagaTimeout.EventStoreIndexRequest.Timebox);
            }
            else if (theId.Equals(typeof(MessageCounterIndex).GetContractId(), StringComparison.OrdinalIgnoreCase))
            {
                job = messageCounterJobFactory.CreateJob(sagaTimeout.EventStoreIndexRequest.Timebox);
            }
            else
            {
                return;
            }

            JobExecutionStatus result = await jobRunner.ExecuteAsync(job).ConfigureAwait(false);

            if (result == JobExecutionStatus.Running)
            {
                RequestTimeout(new RebuildIndexInternal(sagaTimeout.EventStoreIndexRequest, DateTime.UtcNow.AddSeconds(30)));
            }
            else if (result == JobExecutionStatus.Failed)
            {
                // log error
                RequestTimeout(new RebuildIndexInternal(sagaTimeout.EventStoreIndexRequest, DateTime.UtcNow.AddSeconds(30)));
            }
            else if (result == JobExecutionStatus.Completed)
            {
                var finalize = new FinalizeEventStoreIndexRequest(sagaTimeout.EventStoreIndexRequest.Id);
                commandPublisher.Publish(finalize);
            }
        }