diff options
author | Louis <6653109+artonge@users.noreply.github.com> | 2022-01-17 12:42:59 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-17 12:42:59 +0300 |
commit | 22fcd65717f7c78580e314d20160432f5d0286c8 (patch) | |
tree | d5b16a1fec7497fe5cde2df654df07712968f010 | |
parent | 77e24274347a229f7df249b73c9a98a1420dab7e (diff) | |
parent | 67ccb325ef0d456eb22d54656914b43712e9b019 (diff) |
Merge pull request #30633 from nextcloud/backport/30358/stable21
[stable21] Reset job disabling timer on adding the job again
-rw-r--r-- | lib/private/BackgroundJob/JobList.php | 32 |
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(); } /** |