IJobList.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Noveen Sachdeva <noveen.sachdeva@research.iiit.ac.in>
  8. * @author Robin Appelman <robin@icewind.nl>
  9. * @author Robin McCorkell <robin@mccorkell.me.uk>
  10. * @author Côme Chilliet <come.chilliet@nextcloud.com>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OCP\BackgroundJob;
  28. /**
  29. * Interface IJobList
  30. *
  31. * This interface provides functions to register background jobs
  32. *
  33. * To create a new background job create a new class that inherits from either
  34. * \OCP\BackgroundJob\Job, \OCP\BackgroundJob\QueuedJob or
  35. * \OCP\BackgroundJob\TimedJob and register it using ->add($job, $argument),
  36. * $argument will be passed to the run() function of the job when the job is
  37. * executed.
  38. *
  39. * A regular job will be executed every time cron.php is run, a QueuedJob will
  40. * only run once and a TimedJob will only run at a specific interval which is to
  41. * be specified in the constructor of the job by calling
  42. * $this->setInterval($interval) with $interval in seconds.
  43. *
  44. * This interface should be used directly and not implemented by an application.
  45. * The implementation is provided by the server.
  46. *
  47. * @since 7.0.0
  48. */
  49. interface IJobList {
  50. /**
  51. * Add a job to the list
  52. *
  53. * @param IJob|class-string<IJob> $job
  54. * @param mixed $argument The argument to be passed to $job->run() when the job is executed
  55. * @since 7.0.0
  56. */
  57. public function add($job, $argument = null): void;
  58. /**
  59. * Add a job to the list but only run it after the given timestamp
  60. *
  61. * For cron background jobs this means the job will likely run shortly after the timestamp
  62. * has been reached. For ajax background jobs the job might only run when users are active
  63. * on the instance again.
  64. *
  65. * @param class-string<IJob> $job
  66. * @param mixed $argument The serializable argument to be passed to $job->run() when the job is executed
  67. * @since 28.0.0
  68. */
  69. public function scheduleAfter(string $job, int $runAfter, $argument = null): void;
  70. /**
  71. * Remove a job from the list
  72. *
  73. * @param IJob|class-string<IJob> $job
  74. * @param mixed $argument
  75. * @since 7.0.0
  76. */
  77. public function remove($job, $argument = null): void;
  78. /**
  79. * Remove a job from the list by id
  80. *
  81. * @param int $id
  82. * @since 29.0.4
  83. */
  84. public function removeById(int $id): void;
  85. /**
  86. * check if a job is in the list
  87. *
  88. * @param IJob|class-string<IJob> $job
  89. * @param mixed $argument
  90. * @since 7.0.0
  91. */
  92. public function has($job, $argument): bool;
  93. /**
  94. * Get jobs matching the search
  95. *
  96. * @param IJob|class-string<IJob>|null $job
  97. * @return array<IJob>
  98. * @since 25.0.0
  99. * @deprecated 26.0.0 Use getJobsIterator instead to avoid duplicated job objects
  100. */
  101. public function getJobs($job, ?int $limit, int $offset): array;
  102. /**
  103. * Get jobs matching the search
  104. *
  105. * @param IJob|class-string<IJob>|null $job
  106. * @return iterable<IJob>
  107. * @since 26.0.0
  108. */
  109. public function getJobsIterator($job, ?int $limit, int $offset): iterable;
  110. /**
  111. * get the next job in the list
  112. *
  113. * @since 7.0.0 - In 24.0.0 parameter $onlyTimeSensitive got added
  114. */
  115. public function getNext(bool $onlyTimeSensitive = false): ?IJob;
  116. /**
  117. * @since 7.0.0
  118. */
  119. public function getById(int $id): ?IJob;
  120. /**
  121. * @since 23.0.0
  122. */
  123. public function getDetailsById(int $id): ?array;
  124. /**
  125. * set the job that was last ran to the current time
  126. *
  127. * @since 7.0.0
  128. */
  129. public function setLastJob(IJob $job): void;
  130. /**
  131. * Remove the reservation for a job
  132. *
  133. * @since 9.1.0
  134. */
  135. public function unlockJob(IJob $job): void;
  136. /**
  137. * set the lastRun of $job to now
  138. *
  139. * @since 7.0.0
  140. */
  141. public function setLastRun(IJob $job): void;
  142. /**
  143. * set the run duration of $job
  144. *
  145. * @since 12.0.0
  146. */
  147. public function setExecutionTime(IJob $job, int $timeTaken): void;
  148. /**
  149. * Reset the $job so it executes on the next trigger
  150. *
  151. * @since 23.0.0
  152. */
  153. public function resetBackgroundJob(IJob $job): void;
  154. /**
  155. * Checks whether a job of the passed class was reserved to run
  156. * in the last 6h
  157. *
  158. * @param string|null $className
  159. * @return bool
  160. * @since 27.0.0
  161. */
  162. public function hasReservedJob(?string $className): bool;
  163. }