/** * {@inheritdoc} */ public function executeJob(Job $job, VirtualExecution $execution, ProcessEngine $engine) { if ($execution->isTerminated()) { throw new \RuntimeException(sprintf('%s is terminated', $execution)); } $data = (array) $job->getHandlerData(); $command = $data[self::PARAM_COMMAND]; if (!$command instanceof CommandInterface) { throw new \RuntimeException(sprintf('Expecting command, given %s', is_object($command) ? get_class($command) : gettype($command))); } // Move execution to start node if param is set. if (array_key_exists(self::PARAM_NODE_ID, $data)) { $execution->setNode($execution->getProcessModel()->findNode($data[self::PARAM_NODE_ID])); $engine->debug('Moved {execution} to node "{node}"', ['execution' => (string) $execution, 'node' => $execution->getNode()->getId()]); } $engine->debug('Executing async command {cmd} using {execution}', ['cmd' => get_class($command), 'execution' => (string) $execution]); $engine->pushCommand($command); }
/** * {@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; }