コード例 #1
0
        public void RetryCommand(CommandInfo commandInfo, ErrorInfo errorInfo, ActionInfo retrySuccessCallbackAction)
        {
            if (_retryCommandQueue == null)
            {
                _retryCommandQueue = Configuration.Instance.GetRetryCommandQueue();
            }
            var command = commandInfo.Command;

            Action<CommandInfo, ActionInfo> actionAfterCommandRetried = (currentCommandInfo, callbackActionInfo) =>
            {
                currentCommandInfo.IncreaseRetriedCount();
                _logger.InfoFormat("Sent {0} to command retry queue for {1} time.", currentCommandInfo.Command.GetType().Name, currentCommandInfo.RetriedCount);
                callbackActionInfo.Action(callbackActionInfo.Data);
            };

            if (commandInfo.RetriedCount < command.RetryCount)
            {
                if (_retryService.TryAction("TryEnqueueCommand", () => TryEnqueueCommand(command), 2))
                {
                    actionAfterCommandRetried(commandInfo, retrySuccessCallbackAction);
                }
                else
                {
                    _retryService.RetryInQueue(
                        new ActionInfo(
                            "TryEnqueueCommand",
                            (obj) => TryEnqueueCommand(obj as ICommand),
                            command,
                            new ActionInfo(
                                "TryEnqueueCommandFinishedAction",
                                (obj) =>
                                {
                                    var data = obj as dynamic;
                                    var currentCommandInfo = data.CommandInfo as CommandInfo;
                                    var callbackActionInfo = data.Callback as ActionInfo;
                                    actionAfterCommandRetried(currentCommandInfo, callbackActionInfo);
                                    return true;
                                },
                                new { CommandInfo = commandInfo, Callback = retrySuccessCallbackAction },
                                null)));
                }
            }
            else
            {
                _commandAsyncResultManager.TryComplete(commandInfo.Command.Id, errorInfo.ErrorMessage, errorInfo.Exception);
            }
        }
コード例 #2
0
        public void RetryCommand(CommandInfo commandInfo, Exception exception)
        {
            if (_retryCommandQueue == null)
            {
                _retryCommandQueue = Configuration.Instance.GetRetryCommandQueue();
            }

            if (commandInfo.RetriedCount < commandInfo.Command.RetryCount)
            {
                _retryCommandQueue.Enqueue(commandInfo.Command);
                commandInfo.IncreaseRetriedCount();
                _logger.InfoFormat("Sent {0} to command retry queue for {1} time.", commandInfo.Command.GetType().Name, commandInfo.RetriedCount);
            }
            else
            {
                _commandAsyncResultManager.TryComplete(commandInfo.Command.Id, exception.Message, exception);
            }
        }