/** * Consumer callback * * @param AMQPMessage $msg */ public function process(AMQPMessage $msg) { if (!$this->em->isOpen()) { // Entity manager is not open, so terminate throw new TerminateException(); } try { $this->em->clear(); } catch (\Exception $e) { // Cannot clear entity manager, so terminate throw new TerminateException(); } try { // Try to process the message $flag = $this->processMessage($msg); } catch (\Exception $e) { // Stop consuming, because some unhandeled exception during message process occured. throw new TerminateException(); } if ($this->oneRunOnly) { throw (new TerminateException())->withResponse($flag); } else { return $flag; } }
/** * @throws TerminateException */ protected function restartJob(array $request, \Exception $exception = null, $message = null) : int { $this->logger->addError(sprintf('job requeue(%s) for order %d because of %s: %s', $request['retryCounter'], $request['orderId'], get_class($exception), $message ?: $exception->getMessage())); $this->append($this->em->getReference(Order::class, $request['orderId']), $request['retryCounter'] + 1, $request['options']); if (!$this->em->isOpen()) { sleep(self::DELAY_ON_RESTART); throw TerminateException::withResponse(self::MSG_REJECT); } return self::MSG_REJECT; }