コード例 #1
0
        internal async Task Save(SagaScheduling schudele)
        {
            using var context = _serviceProvider.GetRequiredService <SagaContext>();
            await context.ActionSchudele.AddAsync(schudele);

            await context.SaveChangesAsync();
        }
コード例 #2
0
        private async Task ExecuteAsync(SagaScheduling scheduledAction)
        {
            var type = reflectionUtil.GetTypeByName(scheduledAction.Type);

            if (type == null)
            {
                return;
            }

            if (_services.GetService(type)
                is IActionSaga executionAction)
            {
                var sagaState = await stateDAO.GetStateByActionId(scheduledAction.SagaId);

                var typeState = reflectionUtil.GetTypeByName(scheduledAction.TypeState);

                var state = new State(scheduledAction.SagaId);
                if (sagaState != null)
                {
                    state.Value = JsonConvert.DeserializeObject(sagaState.ExtendedData, typeState);
                }

                var action = await actionsDAO.Get(scheduledAction.SagaActionId);

                action.Initiate = DateTime.Now;

                State newState;
                if (scheduledAction.Cancel)
                {
                    newState = await executionAction.CancelAction(state);
                }
                else
                {
                    newState = await executionAction.Handle(state);
                }

                await UpdateState(sagaState, state, newState, action);

                action.Ended  = DateTime.Now;
                action.Status = StatusOperation.Success;
                await actionsDAO.Update(action);
            }
        }