Ejemplo n.º 1
0
        public async Task <SagaResult> GetResult()
        {
            await eventSender.SagaStarted(Id, poleSagasOption.ServiceName, DateTime.UtcNow);

            var executeActivity = GetNextExecuteActivity();

            if (executeActivity == null)
            {
                var expiresAt = DateTime.UtcNow.AddSeconds(poleSagasOption.CompeletedSagaExpiredAfterSeconds);
                await eventSender.SagaEnded(Id, expiresAt);

                return(SagaResult.SuccessResult);
            }
            var result = await RecursiveExecuteActivity(executeActivity);

            return(result);
        }
Ejemplo n.º 2
0
 private async Task GrpcGetSagasCore(CancellationToken cancellationToken)
 {
     using (var stream = sagaClient.GetSagas(new Pole.Sagas.Server.Grpc.GetSagasRequest {
         Limit = options.PreSagasGrpcStreamingResponseLimitCount, ServiceName = options.ServiceName
     }))
     {
         while (await stream.ResponseStream.MoveNext(cancellationToken))
         {
             if (stream.ResponseStream.Current.IsSuccess)
             {
                 try
                 {
                     var sagas = stream.ResponseStream.Current.Sagas.Select(m =>
                     {
                         var result = new SagaEntity
                         {
                             Id = m.Id,
                         };
                         result.ActivityEntities = m.Activities.Select(n => new ActivityEntity
                         {
                             CompensateTimes         = n.CompensateTimes,
                             OvertimeCompensateTimes = n.ExecuteTimes,
                             Id            = n.Id,
                             Name          = n.Name,
                             Order         = n.Order,
                             ParameterData = n.ParameterData,
                             SagaId        = n.SagaId,
                             Status        = n.Status
                         }).ToList();
                         return(result);
                     }).ToList();
                     sagas.ForEach(async sagaEntity =>
                     {
                         var saga             = sagaRestorer.CreateSaga(sagaEntity);
                         var compensateResult = await saga.CompensateWhenRetry();
                         if (compensateResult)
                         {
                             var expiresAt = DateTime.UtcNow.AddSeconds(options.CompeletedSagaExpiredAfterSeconds);
                             await eventSender.SagaEnded(sagaEntity.Id, expiresAt);
                         }
                     });
                 }
                 catch (Exception ex)
                 {
                     logger.LogError(ex, "Errors in NotEndedSagasCompensateRetryBackgroundService CompensateRetry");
                 }
             }
         }
     }
 }