2014-02-11 08:00:24 -05:00
|
|
|
<?php
|
2024-05-23 03:26:56 -04:00
|
|
|
|
2014-02-11 08:00:24 -05:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2014-02-11 08:00:24 -05:00
|
|
|
*/
|
|
|
|
|
namespace OCP\BackgroundJob;
|
|
|
|
|
|
2025-11-24 12:11:53 -05:00
|
|
|
use OCP\AppFramework\Attribute\Consumable;
|
|
|
|
|
|
2015-04-16 11:00:08 -04:00
|
|
|
/**
|
|
|
|
|
* Interface IJobList
|
|
|
|
|
*
|
2018-01-25 18:14:00 -05:00
|
|
|
* This interface provides functions to register background jobs
|
|
|
|
|
*
|
|
|
|
|
* To create a new background job create a new class that inherits from either
|
2024-02-08 05:52:40 -05:00
|
|
|
* \OCP\BackgroundJob\Job, \OCP\BackgroundJob\QueuedJob or
|
|
|
|
|
* \OCP\BackgroundJob\TimedJob and register it using ->add($job, $argument),
|
2018-01-25 18:14:00 -05:00
|
|
|
* $argument will be passed to the run() function of the job when the job is
|
|
|
|
|
* executed.
|
|
|
|
|
*
|
|
|
|
|
* A regular job will be executed every time cron.php is run, a QueuedJob will
|
|
|
|
|
* only run once and a TimedJob will only run at a specific interval which is to
|
|
|
|
|
* be specified in the constructor of the job by calling
|
|
|
|
|
* $this->setInterval($interval) with $interval in seconds.
|
|
|
|
|
*
|
2022-07-11 05:41:47 -04:00
|
|
|
* This interface should be used directly and not implemented by an application.
|
|
|
|
|
* The implementation is provided by the server.
|
|
|
|
|
*
|
2015-04-16 11:00:08 -04:00
|
|
|
* @since 7.0.0
|
|
|
|
|
*/
|
2025-11-24 12:11:53 -05:00
|
|
|
#[Consumable(since: '7.0.0')]
|
2014-02-11 08:00:24 -05:00
|
|
|
interface IJobList {
|
|
|
|
|
/**
|
2014-02-12 07:32:16 -05:00
|
|
|
* Add a job to the list
|
|
|
|
|
*
|
2022-07-11 05:41:47 -04:00
|
|
|
* @param IJob|class-string<IJob> $job
|
2023-05-10 05:56:34 -04:00
|
|
|
* @param mixed $argument The argument to be passed to $job->run() when the job is executed
|
2015-04-16 11:00:08 -04:00
|
|
|
* @since 7.0.0
|
2014-02-11 08:00:24 -05:00
|
|
|
*/
|
2025-11-24 12:11:53 -05:00
|
|
|
public function add(IJob|string $job, mixed $argument = null): void;
|
2023-09-27 08:53:04 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a job to the list but only run it after the given timestamp
|
|
|
|
|
*
|
|
|
|
|
* For cron background jobs this means the job will likely run shortly after the timestamp
|
|
|
|
|
* has been reached. For ajax background jobs the job might only run when users are active
|
|
|
|
|
* on the instance again.
|
|
|
|
|
*
|
|
|
|
|
* @param class-string<IJob> $job
|
|
|
|
|
* @param mixed $argument The serializable argument to be passed to $job->run() when the job is executed
|
|
|
|
|
* @since 28.0.0
|
|
|
|
|
*/
|
2025-11-24 12:11:53 -05:00
|
|
|
public function scheduleAfter(string $job, int $runAfter, mixed $argument = null): void;
|
2014-02-11 08:00:24 -05:00
|
|
|
|
|
|
|
|
/**
|
2014-02-12 07:32:16 -05:00
|
|
|
* Remove a job from the list
|
|
|
|
|
*
|
2022-07-11 05:41:47 -04:00
|
|
|
* @param IJob|class-string<IJob> $job
|
2014-02-11 08:00:24 -05:00
|
|
|
* @param mixed $argument
|
2015-04-16 11:00:08 -04:00
|
|
|
* @since 7.0.0
|
2014-02-11 08:00:24 -05:00
|
|
|
*/
|
2025-11-24 12:11:53 -05:00
|
|
|
public function remove(IJob|string $job, mixed $argument = null): void;
|
2014-02-11 08:00:24 -05:00
|
|
|
|
2024-05-30 09:07:26 -04:00
|
|
|
/**
|
|
|
|
|
* Remove a job from the list by id
|
|
|
|
|
*
|
|
|
|
|
* @since 30.0.0
|
2025-11-24 12:11:53 -05:00
|
|
|
* @since 33.0.0 Parameter $id changed from int to string
|
2024-05-30 09:07:26 -04:00
|
|
|
*/
|
2025-11-24 12:11:53 -05:00
|
|
|
public function removeById(string $id): void;
|
2024-05-30 09:07:26 -04:00
|
|
|
|
2014-02-11 08:00:24 -05:00
|
|
|
/**
|
|
|
|
|
* check if a job is in the list
|
|
|
|
|
*
|
2022-07-11 05:41:47 -04:00
|
|
|
* @param IJob|class-string<IJob> $job
|
2014-02-11 08:00:24 -05:00
|
|
|
* @param mixed $argument
|
2015-04-16 11:00:08 -04:00
|
|
|
* @since 7.0.0
|
2014-02-11 08:00:24 -05:00
|
|
|
*/
|
2025-11-24 12:11:53 -05:00
|
|
|
public function has(IJob|string $job, mixed $argument): bool;
|
2014-02-11 08:00:24 -05:00
|
|
|
|
2022-05-23 06:30:26 -04:00
|
|
|
/**
|
|
|
|
|
* Get jobs matching the search
|
|
|
|
|
*
|
2022-06-27 05:53:10 -04:00
|
|
|
* @param IJob|class-string<IJob>|null $job
|
2023-01-12 11:18:59 -05:00
|
|
|
* @return array<IJob>
|
2022-05-23 06:30:26 -04:00
|
|
|
* @since 25.0.0
|
2023-01-12 11:18:59 -05:00
|
|
|
* @deprecated 26.0.0 Use getJobsIterator instead to avoid duplicated job objects
|
|
|
|
|
*/
|
2025-11-24 12:11:53 -05:00
|
|
|
public function getJobs(IJob|string|null $job, ?int $limit, int $offset): array;
|
2023-01-12 11:18:59 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get jobs matching the search
|
|
|
|
|
*
|
|
|
|
|
* @param IJob|class-string<IJob>|null $job
|
|
|
|
|
* @return iterable<IJob>
|
|
|
|
|
* @since 26.0.0
|
2022-05-23 06:30:26 -04:00
|
|
|
*/
|
2025-11-24 12:11:53 -05:00
|
|
|
public function getJobsIterator(IJob|string|null $job, ?int $limit, int $offset): iterable;
|
2022-05-23 06:30:26 -04:00
|
|
|
|
2014-02-11 08:00:24 -05:00
|
|
|
/**
|
2024-04-09 05:12:48 -04:00
|
|
|
* Get the next job in the list
|
2014-02-11 08:00:24 -05:00
|
|
|
*
|
2024-04-08 11:25:51 -04:00
|
|
|
* @param bool $onlyTimeSensitive Whether we get only time sensitive jobs or not
|
2024-04-09 05:12:48 -04:00
|
|
|
* @param class-string<IJob>[]|null $jobClasses List of job classes to restrict which next job we get
|
|
|
|
|
* @return ?IJob the next job to run. Beware that this object may be a singleton and may be modified by the next call to buildJob.
|
2024-04-08 11:25:51 -04:00
|
|
|
* @since 7.0.0 - In 24.0.0 parameter $onlyTimeSensitive got added; In 30.0.0 parameter $jobClasses got added
|
2014-02-11 08:00:24 -05:00
|
|
|
*/
|
2024-04-08 11:25:51 -04:00
|
|
|
public function getNext(bool $onlyTimeSensitive = false, ?array $jobClasses = null): ?IJob;
|
2014-02-11 08:00:24 -05:00
|
|
|
|
|
|
|
|
/**
|
2015-04-16 11:00:08 -04:00
|
|
|
* @since 7.0.0
|
2025-11-24 12:11:53 -05:00
|
|
|
* @since 33.0.0 Parameter $id changed from int to string
|
2014-02-11 08:00:24 -05:00
|
|
|
*/
|
2025-11-24 12:11:53 -05:00
|
|
|
public function getById(string $id): ?IJob;
|
2014-02-11 08:00:24 -05:00
|
|
|
|
2021-05-31 11:15:26 -04:00
|
|
|
/**
|
2021-10-13 05:46:48 -04:00
|
|
|
* @since 23.0.0
|
2025-11-24 12:11:53 -05:00
|
|
|
* @since 33.0.0 Parameter $id changed from int to string
|
2021-05-31 11:15:26 -04:00
|
|
|
*/
|
2025-11-24 12:11:53 -05:00
|
|
|
public function getDetailsById(string $id): ?array;
|
2021-05-31 11:15:26 -04:00
|
|
|
|
2014-02-11 08:00:24 -05:00
|
|
|
/**
|
2014-02-12 07:32:16 -05:00
|
|
|
* set the job that was last ran to the current time
|
2014-02-11 08:00:24 -05:00
|
|
|
*
|
2015-04-16 11:00:08 -04:00
|
|
|
* @since 7.0.0
|
2014-02-11 08:00:24 -05:00
|
|
|
*/
|
2022-07-11 05:41:47 -04:00
|
|
|
public function setLastJob(IJob $job): void;
|
2014-02-11 08:00:24 -05:00
|
|
|
|
2016-05-18 08:27:48 -04:00
|
|
|
/**
|
|
|
|
|
* Remove the reservation for a job
|
|
|
|
|
*
|
|
|
|
|
* @since 9.1.0
|
|
|
|
|
*/
|
2022-07-11 05:41:47 -04:00
|
|
|
public function unlockJob(IJob $job): void;
|
2016-05-18 08:27:48 -04:00
|
|
|
|
2014-02-11 08:00:24 -05:00
|
|
|
/**
|
|
|
|
|
* set the lastRun of $job to now
|
|
|
|
|
*
|
2015-04-16 11:00:08 -04:00
|
|
|
* @since 7.0.0
|
2014-02-11 08:00:24 -05:00
|
|
|
*/
|
2022-07-11 05:41:47 -04:00
|
|
|
public function setLastRun(IJob $job): void;
|
2017-04-25 11:39:58 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* set the run duration of $job
|
|
|
|
|
*
|
|
|
|
|
* @since 12.0.0
|
|
|
|
|
*/
|
2022-07-11 05:41:47 -04:00
|
|
|
public function setExecutionTime(IJob $job, int $timeTaken): void;
|
2021-05-31 11:15:26 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reset the $job so it executes on the next trigger
|
|
|
|
|
*
|
2021-10-13 05:46:48 -04:00
|
|
|
* @since 23.0.0
|
2021-05-31 11:15:26 -04:00
|
|
|
*/
|
|
|
|
|
public function resetBackgroundJob(IJob $job): void;
|
2023-04-20 06:55:06 -04:00
|
|
|
|
|
|
|
|
/**
|
2023-11-08 10:37:51 -05:00
|
|
|
* Checks whether a job of the passed class was reserved to run
|
|
|
|
|
* in the last 6h
|
2023-04-20 06:55:06 -04:00
|
|
|
*
|
2025-11-24 12:11:53 -05:00
|
|
|
* @param class-string<IJob>|null $className
|
2023-04-20 06:55:06 -04:00
|
|
|
* @return bool
|
|
|
|
|
* @since 27.0.0
|
|
|
|
|
*/
|
|
|
|
|
public function hasReservedJob(?string $className): bool;
|
2023-12-20 08:29:44 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a count of jobs per Job class
|
|
|
|
|
*
|
2025-11-24 12:11:53 -05:00
|
|
|
* @return list<array{class:class-string<IJob>, count:int}>
|
2024-04-09 05:12:48 -04:00
|
|
|
* @since 30.0.0
|
2023-12-20 08:29:44 -05:00
|
|
|
*/
|
|
|
|
|
public function countByClass(): array;
|
2014-02-11 08:00:24 -05:00
|
|
|
}
|