/** * {@inheritdoc} */ public function executeJob(Job $job) { $stmt = $this->engine->prepareQuery("\n\t\t\tUPDATE `#__bpmn_job`\n\t\t\tSET `lock_owner` = :owner,\n\t\t\t\t`locked_at` = :time\n\t\t\tWHERE `id` = :id\n\t\t\tAND (`lock_owner` IS NULL OR `locked_at` < :expires)\n\t\t"); $stmt->bindValue('owner', $this->lockOwner); $stmt->bindValue('time', time()); $stmt->bindValue('expires', time() - $this->lockTimeout); $stmt->bindValue('id', $job->getId()); $locked = $stmt->execute(); if ($locked < 1) { $jobs = $this->engine->getManagementService()->createJobQuery()->jobId($job->getId())->findAll(); if (empty($jobs)) { $this->engine->info('Unable to lock job <{job}> because it does not exist in the DB', ['job' => (string) $job->getId()]); return; } $this->engine->info('Unable to lock job <{job}> because it is locked by job executor "{executor}"', ['job' => (string) $job->getId(), 'executor' => $job->getLockOwner()]); return; } $this->engine->executeCommand(new ExecuteJobCommand($job, $this->findJobHandler($job))); $jobs = $this->engine->getManagementService()->createJobQuery()->jobId($job->getId())->findAll(); if (!empty($jobs)) { $job = array_pop($jobs); if ($job->getRetries() > 0) { $this->engine->info('Re-scheduling job <{job}>, {retries} retries left', ['job' => (string) $job->getId(), 'retries' => $job->getRetries()]); $this->scheduledJobs[] = $job; } } }