Merge pull request #30633 from nextcloud/backport/30358/stable21

[stable21] Reset job disabling timer on adding the job again
This commit is contained in:
Louis 2022-01-17 10:42:59 +01:00 committed by GitHub
commit 22fcd65717
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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();
}
/**