summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/private/BackgroundJob/JobList.php32
1 files changed, 19 insertions, 13 deletions
diff --git a/lib/private/BackgroundJob/JobList.php b/lib/private/BackgroundJob/JobList.php
index 5a89dcdeba6..0e799595939 100644
--- a/lib/private/BackgroundJob/JobList.php
+++ b/lib/private/BackgroundJob/JobList.php
@@ -66,28 +66,34 @@ class JobList implements IJobList {
* @param mixed $argument
*/
public function add($job, $argument = null) {
- if (!$this->has($job, $argument)) {
- if ($job instanceof IJob) {
- $class = get_class($job);
- } else {
- $class = $job;
- }
+ if ($job instanceof IJob) {
+ $class = get_class($job);
+ } else {
+ $class = $job;
+ }
- $argument = json_encode($argument);
- if (strlen($argument) > 4000) {
- throw new \InvalidArgumentException('Background job arguments can\'t exceed 4000 characters (json encoded)');
- }
+ $argumentJson = json_encode($argument);
+ if (strlen($argumentJson) > 4000) {
+ throw new \InvalidArgumentException('Background job arguments can\'t exceed 4000 characters (json encoded)');
+ }
- $query = $this->connection->getQueryBuilder();
+ $query = $this->connection->getQueryBuilder();
+ if (!$this->has($job, $argument)) {
$query->insert('jobs')
->values([
'class' => $query->createNamedParameter($class),
- 'argument' => $query->createNamedParameter($argument),
+ 'argument' => $query->createNamedParameter($argumentJson),
'last_run' => $query->createNamedParameter(0, IQueryBuilder::PARAM_INT),
'last_checked' => $query->createNamedParameter($this->timeFactory->getTime(), IQueryBuilder::PARAM_INT),
]);
- $query->execute();
+ } else {
+ $query->update('jobs')
+ ->set('reserved_at', $query->expr()->literal(0, IQueryBuilder::PARAM_INT))
+ ->set('last_checked', $query->createNamedParameter($this->timeFactory->getTime(), IQueryBuilder::PARAM_INT))
+ ->where($query->expr()->eq('class', $query->createNamedParameter($class)))
+ ->andWhere($query->expr()->eq('argument', $query->createNamedParameter($argumentJson)));
}
+ $query->execute();
}
/**