/** * {@inheritdoc} */ protected function executeCommand(ProcessEngine $engine) { $execution = $engine->findExecution($this->job->getExecutionId()); $engine->debug('Executing job <{job}> using handler "{handler}" ({impl}) within {execution}', ['job' => (string) $this->job->getId(), 'handler' => $this->handler->getType(), 'impl' => get_class($this->handler), 'execution' => (string) $execution]); try { $this->handler->executeJob($this->job, $execution, $engine); // Delete job when it has been completed successfully. $engine->getConnection()->delete('#__bpmn_job', ['id' => $this->job->getId()]); } catch (\Exception $e) { $engine->warning('Job <{job}> failed with exception {exception}: "{message}"', ['job' => (string) $this->job->getId(), 'exception' => get_class($e), 'message' => $e->getMessage()]); $stmt = $engine->prepareQuery("\n\t\t\t\tUPDATE `#__bpmn_job`\n\t\t\t\tSET `retries` = `retries` - 1,\n\t\t\t\t\t`scheduled_at` = NULL,\n\t\t\t\t\t`lock_owner` = NULL,\n\t\t\t\t\t`locked_at` = NULL,\n\t\t\t\t\t`exception_type` = :type,\n\t\t\t\t\t`exception_message` = :message,\n\t\t\t\t\t`exception_data` = :data\n\t\t\t\tWHERE `id` = :id\n\t\t\t"); $stmt->bindValue('id', $this->job->getId()); $stmt->bindValue('type', get_class($e)); $stmt->bindValue('message', (string) $e->getMessage()); $stmt->bindValue('data', new BinaryData(serialize($e->getTraceAsString()))); $stmt->execute(); } }
/** * {@inheritdoc} */ public function registerJobHandler(JobHandlerInterface $handler) { $this->handlers[$handler->getType()] = $handler; }