2014-02-11 08:00:24 -05:00
|
|
|
<?php
|
|
|
|
|
/**
|
2016-07-21 11:07:57 -04:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
|
*
|
|
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2015-03-26 06:44:34 -04:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2017-11-06 09:56:42 -05:00
|
|
|
* @author Noveen Sachdeva <noveen.sachdeva@research.iiit.ac.in>
|
2016-07-21 12:13:36 -04:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-01-12 09:02:16 -05:00
|
|
|
* @author Robin McCorkell <robin@mccorkell.me.uk>
|
2022-07-11 05:41:47 -04:00
|
|
|
* @author Côme Chilliet <come.chilliet@nextcloud.com>
|
2015-03-26 06:44:34 -04:00
|
|
|
*
|
|
|
|
|
* @license AGPL-3.0
|
|
|
|
|
*
|
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 13:57:53 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-03-26 06:44:34 -04:00
|
|
|
*
|
2014-02-11 08:00:24 -05:00
|
|
|
*/
|
|
|
|
|
namespace OCP\BackgroundJob;
|
|
|
|
|
|
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
|
|
|
|
|
*/
|
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
|
|
|
*/
|
2022-07-11 05:41:47 -04:00
|
|
|
public function add($job, $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
|
|
|
|
|
*/
|
|
|
|
|
public function scheduleAfter(string $job, int $runAfter, $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
|
|
|
*/
|
2022-07-11 05:41:47 -04:00
|
|
|
public function remove($job, $argument = null): void;
|
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
|
|
|
*/
|
2022-07-11 05:41:47 -04:00
|
|
|
public function has($job, $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
|
|
|
|
|
*/
|
|
|
|
|
public function getJobs($job, ?int $limit, int $offset): array;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
*/
|
2023-01-12 11:18:59 -05:00
|
|
|
public function getJobsIterator($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
|
2014-02-11 08:00:24 -05:00
|
|
|
*/
|
2022-07-11 05:41:47 -04:00
|
|
|
public function getById(int $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
|
2021-05-31 11:15:26 -04:00
|
|
|
*/
|
|
|
|
|
public function getDetailsById(int $id): ?array;
|
|
|
|
|
|
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
|
|
|
*
|
|
|
|
|
* @param string|null $className
|
|
|
|
|
* @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
|
|
|
|
|
*
|
|
|
|
|
* @return list<array{class:class-string, 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
|
|
|
}
|