コード例 #1
0
ファイル: RetryHandler.php プロジェクト: rezzza/command-bus
 public function retry(RetryCommand $command)
 {
     if ($this->logger) {
         $this->logger->info(sprintf('[RETRY] command [%s] , tentative number %d', get_class($command->getCommand()), $command->getTryCount()));
     }
     try {
         $this->commandBus->handle($command->getCommand());
     } catch (\Exception $e) {
         throw new CommandHandlerFailedException($command, $e);
     }
 }
コード例 #2
0
 public function onFail(CommandHandlerFailedException $exception)
 {
     $command = $exception->getCommand();
     if ($command instanceof RetryCommand) {
         if ($command->getTryCount() === $this->failOnCount) {
             $command = new FailedCommand($command->getCommand(), $this->failOnCount);
         } else {
             $command->incrementTryCount();
         }
     } elseif ($command instanceof FailedCommand) {
         if ($this->logger) {
             $this->logger->error(sprintf('[RetryThenFailStrategy] command [%s] go to failed queue.', get_class($command->getCommand())));
         }
         if ($this->requeueOnFail) {
             $command->incrementTryCount();
         } else {
             return;
         }
     } else {
         $command = new RetryCommand($command);
     }
     if ($this->logger) {
         $this->logger->error(sprintf('[RetryThenFailStrategy] command [%s] failed, attemps %d.', get_class($command->getCommand()), $command->getTryCount()));
     }
     $this->commandBus->handle($command, $this->priority);
 }