public function execute($payload, ExecutionContext $context)
 {
     $process = $this->createProcess($payload);
     $process->run(function ($type, $buffer) use($context) {
         if (Process::ERR === $type) {
             $context->getLogger()->error($buffer);
         } else {
             $context->getLogger()->debug($buffer);
         }
     });
 }
Example #2
0
 /**
  * @return bool True if a task was processed, false otherwise.
  */
 public function execute()
 {
     $logger = $this->context->getLogger();
     try {
         $payload = $this->context->getQueue()->pop();
     } catch (NoItemAvailableException $e) {
         $logger->debug($e->getMessage());
         return false;
     }
     $logger->info('Start executing.', ['payload' => $payload]);
     try {
         $this->adapter->execute($payload, $this->context);
         $logger->info('Payload was successfully executed.', ['payload' => $payload]);
     } catch (\Exception $e) {
         $logger->error(sprintf('An error occurred while executing payload: %s.', $e->getMessage()), ['payload' => $payload]);
     }
     return true;
 }