IJob.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCP\BackgroundJob;
  8. use OCP\ILogger;
  9. /**
  10. * This interface represents a background job run with cron
  11. *
  12. * To implement a background job, you must extend either \OCP\BackgroundJob\Job,
  13. * \OCP\BackgroundJob\TimedJob or \OCP\BackgroundJob\QueuedJob
  14. *
  15. * @since 7.0.0
  16. */
  17. interface IJob {
  18. /**
  19. * @since 24.0.0
  20. */
  21. public const TIME_INSENSITIVE = 0;
  22. /**
  23. * @since 24.0.0
  24. */
  25. public const TIME_SENSITIVE = 1;
  26. /**
  27. * Run the background job with the registered argument
  28. *
  29. * @param IJobList $jobList The job list that manages the state of this job
  30. * @param ILogger|null $logger
  31. * @since 7.0.0
  32. * @deprecated 25.0.0 Use start() instead. This method will be removed
  33. * with the ILogger interface
  34. */
  35. public function execute(IJobList $jobList, ?ILogger $logger = null);
  36. /**
  37. * Start the background job with the registered argument
  38. *
  39. * This methods will take care of running the background job, of initializing
  40. * the state and cleaning up the job list after running the job.
  41. *
  42. * For common background job scenario, you will want to use TimedJob or QueuedJob
  43. * instead of overwritting this method.
  44. *
  45. * @param IJobList $jobList The job list that manages the state of this job
  46. * @since 25.0.0
  47. */
  48. public function start(IJobList $jobList): void;
  49. /**
  50. * @since 7.0.0
  51. */
  52. public function setId(int $id);
  53. /**
  54. * @since 7.0.0
  55. */
  56. public function setLastRun(int $lastRun);
  57. /**
  58. * @param mixed $argument
  59. * @since 7.0.0
  60. */
  61. public function setArgument($argument);
  62. /**
  63. * Get the id of the background job
  64. * This id is determined by the job list when a job is added to the list
  65. *
  66. * @return int
  67. * @since 7.0.0
  68. */
  69. public function getId();
  70. /**
  71. * Get the last time this job was run as unix timestamp
  72. *
  73. * @return int
  74. * @since 7.0.0
  75. */
  76. public function getLastRun();
  77. /**
  78. * Get the argument associated with the background job
  79. * This is the argument that will be passed to the background job
  80. *
  81. * @return mixed
  82. * @since 7.0.0
  83. */
  84. public function getArgument();
  85. }