示例#1
0
 /** {@inheritDoc} */
 public function process(Message $message, array $options)
 {
     $result = $this->processor->process($message, $options);
     $properties = $message->getProperties();
     if (!isset($properties['reply_to'], $properties['correlation_id']) || empty($properties['reply_to']) || empty($properties['correlation_id'])) {
         return $result;
     }
     $this->logger and $this->logger->info(sprintf('sending a new message to the "%s" queue with the id "%s"', $properties['reply_to'], $properties['correlation_id']), ['swarrot_processor' => 'rpc']);
     $message = new Message((string) $result, ['correlation_id' => $properties['correlation_id']]);
     $this->publisher->publish($message, $properties['reply_to']);
     return $result;
 }
示例#2
0
 public function process(Message $message, array $options)
 {
     $properties = $message->getProperties();
     $body = json_decode($message->getBody(), true);
     if (!isset($properties['wisembly_attempts'])) {
         $properties['wisembly_attempts'] = 0;
     }
     if (!isset($body['arguments'])) {
         $body['arguments'] = [];
     }
     // add environment
     $body['arguments'][] = '--env';
     $body['arguments'][] = $this->environment;
     // add verbosity
     switch ($this->verbosity) {
         case OutputInterface::VERBOSITY_DEBUG:
             $body['arguments'][] = '-vvv';
             break;
         case OutputInterface::VERBOSITY_VERY_VERBOSE:
             $body['arguments'][] = '-vv';
             break;
         case OutputInterface::VERBOSITY_VERBOSE:
             $body['arguments'][] = '--verbose';
             break;
         case OutputInterface::VERBOSITY_QUIET:
             $body['arguments'][] = '--quiet';
             break;
         case OutputInterface::VERBOSITY_NORMAL:
             break;
     }
     ++$properties['wisembly_attempts'];
     $this->logger->info('Dispatching command', $body);
     // if no proper command given, log it and nack
     if (!isset($body['command'])) {
         $this->logger->critical('No proper command found in message', ['body' => $body]);
         $this->provider->nack($message, false);
         return;
     }
     $this->builder->setPrefix([PHP_BINARY, $this->commandPath, $body['command']]);
     $this->builder->setArguments($body['arguments']);
     $process = $this->builder->getProcess();
     $process->run(function ($type, $data) {
         switch ($type) {
             case Process::OUT:
                 $this->logger->info($data);
                 break;
             case Process::ERR:
                 $this->logger->error($data);
                 break;
         }
     });
     // reset the builder
     $this->builder->setArguments([]);
     $this->builder->setPrefix([]);
     if ($process->isSuccessful()) {
         $this->logger->info('The process was successful', $body);
         $this->provider->ack($message);
         return;
     }
     $code = $process->getExitCode();
     $this->logger->error('The command failed ; aborting', ['body' => $body, 'code' => $code]);
     $this->provider->nack($message, false);
     // should we requeue it ?
     if (static::REQUEUE === $code && $properties['wisembly_attempts'] < static::MAX_ATTEMPTS) {
         $this->logger->notice('Retrying...', $body);
         $message = new Message($message->getBody(), $properties, $message->getId());
         $this->publisher->publish($message);
     }
 }