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
|
|
|
|
|
* \OC\BackgroundJob\Job, \OC\BackgroundJob\QueuedJob or
|
|
|
|
|
* \OC\BackgroundJob\TimedJob and register it using ->add($job, $argument),
|
|
|
|
|
* $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;
|
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
|
|
|
/**
|
|
|
|
|
* get the next job in the list
|
|
|
|
|
*
|
2022-01-31 11:56:43 -05:00
|
|
|
* @since 7.0.0 - In 24.0.0 parameter $onlyTimeSensitive got added
|
2014-02-11 08:00:24 -05:00
|
|
|
*/
|
2022-01-31 11:56:43 -05:00
|
|
|
public function getNext(bool $onlyTimeSensitive = false): ?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
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks whether a job of the passed class is reserved to run
|
|
|
|
|
*
|
|
|
|
|
* @param string|null $className
|
|
|
|
|
* @return bool
|
|
|
|
|
* @since 27.0.0
|
|
|
|
|
*/
|
|
|
|
|
public function hasReservedJob(?string $className): bool;
|
2014-02-11 08:00:24 -05:00
|
|
|
}
|