aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/BackgroundJob
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2023-09-27 14:53:04 +0200
committerChristoph Wurst <christoph@winzerhof-wurst.at>2023-09-29 10:29:40 +0200
commit04ecc2a6a95a3c996b496b851cabc201f9716ebb (patch)
tree633b540b89ec7c68d0e4d8fd6f8ec727c9811b81 /lib/private/BackgroundJob
parentf8f437072ac13a4556dea18219d55f11466497e5 (diff)
downloadnextcloud-server-04ecc2a6a95a3c996b496b851cabc201f9716ebb.tar.gz
nextcloud-server-04ecc2a6a95a3c996b496b851cabc201f9716ebb.zip
feat(backgroundjob): Schedule job after <timestamp>
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/private/BackgroundJob')
-rw-r--r--lib/private/BackgroundJob/JobList.php21
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/private/BackgroundJob/JobList.php b/lib/private/BackgroundJob/JobList.php
index 36cccbd4eab..2b42e2ff1ee 100644
--- a/lib/private/BackgroundJob/JobList.php
+++ b/lib/private/BackgroundJob/JobList.php
@@ -41,6 +41,10 @@ use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IConfig;
use OCP\IDBConnection;
use Psr\Log\LoggerInterface;
+use function get_class;
+use function json_encode;
+use function md5;
+use function strlen;
class JobList implements IJobList {
protected IDBConnection $connection;
@@ -55,11 +59,10 @@ class JobList implements IJobList {
$this->logger = $logger;
}
- /**
- * @param IJob|class-string<IJob> $job
- * @param mixed $argument
- */
- public function add($job, $argument = null): void {
+ public function add($job, $argument = null, int $firstCheck = null): void {
+ if ($firstCheck === null) {
+ $firstCheck = $this->timeFactory->getTime();
+ }
if ($job instanceof IJob) {
$class = get_class($job);
} else {
@@ -79,18 +82,22 @@ class JobList implements IJobList {
'argument' => $query->createNamedParameter($argumentJson),
'argument_hash' => $query->createNamedParameter(md5($argumentJson)),
'last_run' => $query->createNamedParameter(0, IQueryBuilder::PARAM_INT),
- 'last_checked' => $query->createNamedParameter($this->timeFactory->getTime(), IQueryBuilder::PARAM_INT),
+ 'last_checked' => $query->createNamedParameter($firstCheck, IQueryBuilder::PARAM_INT),
]);
} 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))
+ ->set('last_checked', $query->createNamedParameter($firstCheck, IQueryBuilder::PARAM_INT))
->where($query->expr()->eq('class', $query->createNamedParameter($class)))
->andWhere($query->expr()->eq('argument_hash', $query->createNamedParameter(md5($argumentJson))));
}
$query->executeStatement();
}
+ public function scheduleAfter(string $job, int $runAfter, $argument = null): void {
+ $this->add($job, $argument, $runAfter);
+ }
+
/**
* @param IJob|string $job
* @param mixed $argument