Пример #1
0
 /**
  * {@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();
     }
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function scheduleJob(UUID $executionId, $handlerType, $data, \DateTimeInterface $runAt = NULL)
 {
     $id = UUID::createRandom();
     $handlerType = (string) $handlerType;
     $job = new Job($id, $executionId, $handlerType, $data);
     $job->setRunAt($runAt);
     $time = $job->getRunAt();
     if ($time !== NULL) {
         $time = $time->getTimestamp();
     }
     $this->engine->getConnection()->insert('#__bpmn_job', ['id' => $job->getId(), 'execution_id' => $job->getExecutionId(), 'handler_type' => $job->getHandlerType(), 'handler_data' => new BinaryData(serialize($job->getHandlerData())), 'created_at' => time(), 'run_at' => $time]);
     $this->engine->info('Created job <{job}> of type "{handler}" targeting execution <{execution}>', ['job' => (string) $job->getId(), 'handler' => $handlerType, 'execution' => (string) $executionId]);
     return $this->scheduledJobs[] = $job;
 }