diff options
author | MichaIng <micha@dietpi.com> | 2022-01-12 18:02:12 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-12 18:02:12 +0300 |
commit | 12d92650fd67f11b5390d039e8b812a33f120ca9 (patch) | |
tree | 3548e369578a96e335628278a9b750158e3d1582 /lib | |
parent | 29a3f2cd232b81ebaaa0667d6997d02264407a04 (diff) | |
parent | 96e520584a4888ae26086c626c8dc58de47572fe (diff) |
Merge pull request #30622 from nextcloud/backport/30358/stable22
[stable22] Reset job disabling timer on adding the job again
Diffstat (limited to 'lib')
-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 f3b96dcbb7b..693c7af5ea1 100644 --- a/lib/private/BackgroundJob/JobList.php +++ b/lib/private/BackgroundJob/JobList.php @@ -65,28 +65,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->executeStatement(); } /** |