Skip to content

Commit 22fcd65

Browse files
authored
Merge pull request #30633 from nextcloud/backport/30358/stable21
[stable21] Reset job disabling timer on adding the job again
2 parents 77e2427 + 67ccb32 commit 22fcd65

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

lib/private/BackgroundJob/JobList.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,34 @@ public function __construct(IDBConnection $connection, IConfig $config, ITimeFac
6666
* @param mixed $argument
6767
*/
6868
public function add($job, $argument = null) {
69-
if (!$this->has($job, $argument)) {
70-
if ($job instanceof IJob) {
71-
$class = get_class($job);
72-
} else {
73-
$class = $job;
74-
}
69+
if ($job instanceof IJob) {
70+
$class = get_class($job);
71+
} else {
72+
$class = $job;
73+
}
7574

76-
$argument = json_encode($argument);
77-
if (strlen($argument) > 4000) {
78-
throw new \InvalidArgumentException('Background job arguments can\'t exceed 4000 characters (json encoded)');
79-
}
75+
$argumentJson = json_encode($argument);
76+
if (strlen($argumentJson) > 4000) {
77+
throw new \InvalidArgumentException('Background job arguments can\'t exceed 4000 characters (json encoded)');
78+
}
8079

81-
$query = $this->connection->getQueryBuilder();
80+
$query = $this->connection->getQueryBuilder();
81+
if (!$this->has($job, $argument)) {
8282
$query->insert('jobs')
8383
->values([
8484
'class' => $query->createNamedParameter($class),
85-
'argument' => $query->createNamedParameter($argument),
85+
'argument' => $query->createNamedParameter($argumentJson),
8686
'last_run' => $query->createNamedParameter(0, IQueryBuilder::PARAM_INT),
8787
'last_checked' => $query->createNamedParameter($this->timeFactory->getTime(), IQueryBuilder::PARAM_INT),
8888
]);
89-
$query->execute();
89+
} else {
90+
$query->update('jobs')
91+
->set('reserved_at', $query->expr()->literal(0, IQueryBuilder::PARAM_INT))
92+
->set('last_checked', $query->createNamedParameter($this->timeFactory->getTime(), IQueryBuilder::PARAM_INT))
93+
->where($query->expr()->eq('class', $query->createNamedParameter($class)))
94+
->andWhere($query->expr()->eq('argument', $query->createNamedParameter($argumentJson)));
9095
}
96+
$query->execute();
9197
}
9298

9399
/**

0 commit comments

Comments
 (0)