IJob.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Robin Appelman <robin@icewind.nl>
  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. use OCP\ILogger;
  29. /**
  30. * This interface represend a backgroud job run with cron
  31. *
  32. * To implement a background job, you must extend either \OCP\BackgroundJob\Job,
  33. * \OCP\BackgroundJob\TimedJob or \OCP\BackgroundJob\QueuedJob
  34. *
  35. * @since 7.0.0
  36. */
  37. interface IJob {
  38. /**
  39. * @since 24.0.0
  40. */
  41. public const TIME_INSENSITIVE = 0;
  42. /**
  43. * @since 24.0.0
  44. */
  45. public const TIME_SENSITIVE = 1;
  46. /**
  47. * Run the background job with the registered argument
  48. *
  49. * @param IJobList $jobList The job list that manages the state of this job
  50. * @param ILogger|null $logger
  51. * @since 7.0.0
  52. * @deprecated since 25.0.0 Use start() instead. This method will be removed
  53. * with the ILogger interface
  54. */
  55. public function execute(IJobList $jobList, ILogger $logger = null);
  56. /**
  57. * Start the background job with the registered argument
  58. *
  59. * This methods will take care of running the background job, of initializing
  60. * the state and cleaning up the job list after running the job.
  61. *
  62. * For common background job scenario, you will want to use TimedJob or QueuedJob
  63. * instead of overwritting this method.
  64. *
  65. * @param IJobList $jobList The job list that manages the state of this job
  66. * @since 25.0.0
  67. */
  68. public function start(IJobList $jobList): void;
  69. /**
  70. * @since 7.0.0
  71. */
  72. public function setId(int $id);
  73. /**
  74. * @since 7.0.0
  75. */
  76. public function setLastRun(int $lastRun);
  77. /**
  78. * @param mixed $argument
  79. * @since 7.0.0
  80. */
  81. public function setArgument($argument);
  82. /**
  83. * Get the id of the background job
  84. * This id is determined by the job list when a job is added to the list
  85. *
  86. * @return int
  87. * @since 7.0.0
  88. */
  89. public function getId();
  90. /**
  91. * Get the last time this job was run as unix timestamp
  92. *
  93. * @return int
  94. * @since 7.0.0
  95. */
  96. public function getLastRun();
  97. /**
  98. * Get the argument associated with the background job
  99. * This is the argument that will be passed to the background job
  100. *
  101. * @return mixed
  102. * @since 7.0.0
  103. */
  104. public function getArgument();
  105. }