diff options
author | Julius Härtl <jus@bitgrid.net> | 2021-12-21 08:05:50 +0100 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2022-01-03 12:12:02 +0100 |
commit | b30193ed14d638cd514c1dadb98a1e9cbc31d67a (patch) | |
tree | 0f6aee01c40e60797f5e67141426f79ad94586bd | |
parent | eb65e653d38b14a424279f95e8639713a41aeba6 (diff) | |
download | nextcloud-server-b30193ed14d638cd514c1dadb98a1e9cbc31d67a.tar.gz nextcloud-server-b30193ed14d638cd514c1dadb98a1e9cbc31d67a.zip |
Reset job disabling timer on adding the job again
Signed-off-by: Julius Härtl <jus@bitgrid.net>
-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 9d8d1d836b6..9442bd9eca9 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(); } /** |