/** * get the next job in the list * * @return IJob|null */ public function getNext() { $query = $this->connection->getQueryBuilder(); $query->select('*')->from('jobs')->where($query->expr()->lte('reserved_at', $query->createNamedParameter($this->timeFactory->getTime() - 12 * 3600, IQueryBuilder::PARAM_INT)))->orderBy('last_checked', 'ASC')->setMaxResults(1); $update = $this->connection->getQueryBuilder(); $update->update('jobs')->set('reserved_at', $update->createNamedParameter($this->timeFactory->getTime()))->set('last_checked', $update->createNamedParameter($this->timeFactory->getTime()))->where($update->expr()->eq('id', $update->createParameter('jobid'))); $this->connection->lockTable('jobs'); $result = $query->execute(); $row = $result->fetch(); $result->closeCursor(); if ($row) { $update->setParameter('jobid', $row['id']); $update->execute(); $this->connection->unlockTable(); $job = $this->buildJob($row); if ($job === null) { // Background job from disabled app, try again. return $this->getNext(); } return $job; } else { $this->connection->unlockTable(); return null; } }
/** * @inheritdoc */ public function unlockTable() { $this->connection->unlockTable(); }