make JobList::next() lock free
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
parent
35b1f23d11
commit
1bc28261d5
|
@ -187,18 +187,24 @@ class JobList implements IJobList {
|
||||||
$update->update('jobs')
|
$update->update('jobs')
|
||||||
->set('reserved_at', $update->createNamedParameter($this->timeFactory->getTime()))
|
->set('reserved_at', $update->createNamedParameter($this->timeFactory->getTime()))
|
||||||
->set('last_checked', $update->createNamedParameter($this->timeFactory->getTime()))
|
->set('last_checked', $update->createNamedParameter($this->timeFactory->getTime()))
|
||||||
->where($update->expr()->eq('id', $update->createParameter('jobid')));
|
->where($update->expr()->eq('id', $update->createParameter('jobid')))
|
||||||
|
->andWhere($update->expr()->eq('reserved_at', $update->createParameter('reserved_at')))
|
||||||
|
->andWhere($update->expr()->eq('last_checked', $update->createParameter('last_checked')));
|
||||||
|
|
||||||
$this->connection->lockTable('jobs');
|
|
||||||
$result = $query->execute();
|
$result = $query->execute();
|
||||||
$row = $result->fetch();
|
$row = $result->fetch();
|
||||||
$result->closeCursor();
|
$result->closeCursor();
|
||||||
|
|
||||||
if ($row) {
|
if ($row) {
|
||||||
$update->setParameter('jobid', $row['id']);
|
$update->setParameter('jobid', $row['id']);
|
||||||
$update->execute();
|
$update->setParameter('reserved_at', $row['reserved_at']);
|
||||||
$this->connection->unlockTable();
|
$update->setParameter('last_checked', $row['last_checked']);
|
||||||
|
$count = $update->execute();
|
||||||
|
|
||||||
|
if ($count === 0) {
|
||||||
|
// Background job already executed elsewhere, try again.
|
||||||
|
return $this->getNext();
|
||||||
|
}
|
||||||
$job = $this->buildJob($row);
|
$job = $this->buildJob($row);
|
||||||
|
|
||||||
if ($job === null) {
|
if ($job === null) {
|
||||||
|
@ -208,7 +214,6 @@ class JobList implements IJobList {
|
||||||
|
|
||||||
return $job;
|
return $job;
|
||||||
} else {
|
} else {
|
||||||
$this->connection->unlockTable();
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue