IJobList.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCP\BackgroundJob;
  27. /**
  28. * Interface IJobList
  29. *
  30. * This interface provides functions to register background jobs
  31. *
  32. * To create a new background job create a new class that inherits from either
  33. * \OC\BackgroundJob\Job, \OC\BackgroundJob\QueuedJob or
  34. * \OC\BackgroundJob\TimedJob and register it using ->add($job, $argument),
  35. * $argument will be passed to the run() function of the job when the job is
  36. * executed.
  37. *
  38. * A regular job will be executed every time cron.php is run, a QueuedJob will
  39. * only run once and a TimedJob will only run at a specific interval which is to
  40. * be specified in the constructor of the job by calling
  41. * $this->setInterval($interval) with $interval in seconds.
  42. *
  43. * @package OCP\BackgroundJob
  44. * @since 7.0.0
  45. */
  46. interface IJobList {
  47. /**
  48. * Add a job to the list
  49. *
  50. * @param \OCP\BackgroundJob\IJob|string $job
  51. * @param mixed $argument The argument to be passed to $job->run() when the job is exectured
  52. * @since 7.0.0
  53. */
  54. public function add($job, $argument = null);
  55. /**
  56. * Remove a job from the list
  57. *
  58. * @param \OCP\BackgroundJob\IJob|string $job
  59. * @param mixed $argument
  60. * @since 7.0.0
  61. */
  62. public function remove($job, $argument = null);
  63. /**
  64. * check if a job is in the list
  65. *
  66. * @param \OCP\BackgroundJob\IJob|string $job
  67. * @param mixed $argument
  68. * @return bool
  69. * @since 7.0.0
  70. */
  71. public function has($job, $argument);
  72. /**
  73. * get all jobs in the list
  74. *
  75. * @return \OCP\BackgroundJob\IJob[]
  76. * @since 7.0.0
  77. * @deprecated 9.0.0 - This method is dangerous since it can cause load and
  78. * memory problems when creating too many instances.
  79. */
  80. public function getAll();
  81. /**
  82. * get the next job in the list
  83. *
  84. * @return \OCP\BackgroundJob\IJob|null
  85. * @since 7.0.0
  86. */
  87. public function getNext();
  88. /**
  89. * @param int $id
  90. * @return \OCP\BackgroundJob\IJob|null
  91. * @since 7.0.0
  92. */
  93. public function getById($id);
  94. /**
  95. * set the job that was last ran to the current time
  96. *
  97. * @param \OCP\BackgroundJob\IJob $job
  98. * @since 7.0.0
  99. */
  100. public function setLastJob(IJob $job);
  101. /**
  102. * Remove the reservation for a job
  103. *
  104. * @param IJob $job
  105. * @since 9.1.0
  106. */
  107. public function unlockJob(IJob $job);
  108. /**
  109. * get the id of the last ran job
  110. *
  111. * @return int
  112. * @since 7.0.0
  113. * @deprecated 9.1.0 - The functionality behind the value is deprecated, it
  114. * only tells you which job finished last, but since we now allow multiple
  115. * executors to run in parallel, it's not used to calculate the next job.
  116. */
  117. public function getLastJob();
  118. /**
  119. * set the lastRun of $job to now
  120. *
  121. * @param IJob $job
  122. * @since 7.0.0
  123. */
  124. public function setLastRun(IJob $job);
  125. /**
  126. * set the run duration of $job
  127. *
  128. * @param IJob $job
  129. * @param $timeTaken
  130. * @since 12.0.0
  131. */
  132. public function setExecutionTime(IJob $job, $timeTaken);
  133. }