示例#1
0
 public async Task Route(NoResultCommandWrapper command, ILambdaContext context)
 {
     try
     {
         var executer = ServiceProvider.Value.GetService <IDirectCommandExecuter>();
         Console.WriteLine(command.Command.GetType());
         await executer.ExecuteAsync(command);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Demystify());
     }
 }
示例#2
0
        public async Task <bool> HandleRecievedItemAsync <TCommand>(QueueItem <TCommand> item, int maxDequeueCount) where TCommand : class, ICommand
        {
            try
            {
                _logger.LogInfo($"Recieved command {item.GetType().Name} from queue");
                bool shouldDequeue = true;
                // ReSharper disable once SuspiciousTypeConversion.Global - IQueueableCommand is implemented by package users
                IQueueableCommand queueableCommand = item.Item as IQueueableCommand;
                if (queueableCommand != null)
                {
                    queueableCommand.DequeueCount = item.DequeueCount;
                }
                NoResultCommandWrapper wrappedCommand = new NoResultCommandWrapper(item.Item);
                Task commandTask = _commandExecuter.ExecuteAsync(wrappedCommand);
                while (!commandTask.Wait(TimeSpan.FromSeconds(10)))
                {
                    await item.ExtendLeaseAsync();
                }

                if (queueableCommand != null)
                {
                    shouldDequeue = queueableCommand.ShouldDequeue;
                }
                _logger.LogInfo($"Completed processing command {item.GetType().Name} and returning a shouldDequeue status of {shouldDequeue}");
                return(shouldDequeue);
            }
            catch (Exception ex)
            {
                if (item.DequeueCount > maxDequeueCount)
                {
                    _logger.LogError($"Error during processing command of type {item.GetType().Name} with exception of type {ex.GetType().AssemblyQualifiedName}. Dequeue count is {item.DequeueCount}, will not try again.", item.Item, ex);
                    return(true);
                }
                _logger.LogWarning($"Error during processing command of type {item.GetType().Name} with exception of type {ex.GetType().AssemblyQualifiedName}. Dequeue count is {item.DequeueCount}, will try again.", item.Item, ex);
                return(false);
            }
        }
示例#3
0
        private async Task ExecuteActorForCommandWithNoResult(ICommandHandler handler, NoResultCommandWrapper wrappedCommand, CancellationToken cancellationToken)
        {
            Delegate dlg = _commandHandlerExecuters[handler.GetType()];

            if (handler is ICancellableCommandHandler)
            {
                Func <ICommandHandler, ICommand, CancellationToken, Task> func = (Func <ICommandHandler, ICommand, CancellationToken, Task>)dlg;
                await func(handler, wrappedCommand.Command, cancellationToken);
            }
            else
            {
                Func <ICommandHandler, ICommand, Task> func = (Func <ICommandHandler, ICommand, Task>)dlg;
                await func(handler, wrappedCommand.Command);
            }
        }