mirror of
https://github.com/nextcloud/server.git
synced 2026-06-08 08:16:43 -04:00
Merge pull request #30633 from nextcloud/backport/30358/stable21
[stable21] Reset job disabling timer on adding the job again
This commit is contained in:
commit
22fcd65717
1 changed files with 20 additions and 14 deletions
|
|
@ -66,28 +66,34 @@ class JobList implements IJobList {
|
|||
* @param mixed $argument
|
||||
*/
|
||||
public function add($job, $argument = null) {
|
||||
if ($job instanceof IJob) {
|
||||
$class = get_class($job);
|
||||
} else {
|
||||
$class = $job;
|
||||
}
|
||||
|
||||
$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();
|
||||
if (!$this->has($job, $argument)) {
|
||||
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)');
|
||||
}
|
||||
|
||||
$query = $this->connection->getQueryBuilder();
|
||||
$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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue