RunnableJob.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Job queue task instance that can be executed via a run() method
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. * http://www.gnu.org/copyleft/gpl.html
  19. *
  20. * @file
  21. */
  22. /**
  23. * Job that has a run() method and metadata accessors for JobQueue::pop() and JobQueue::ack()
  24. *
  25. * Instances are not only enqueueable via JobQueue::push(), but they can also be executed by
  26. * by calling their run() method. When constructing a job to be enqueued via JobQueue::push(),
  27. * it will not be possible to construct a RunnableJob instance if the class for that job is not
  28. * loaded by the application for the local DB domain. In that case, the general-purpose
  29. * JobSpecification class can be used instead.
  30. *
  31. * @ingroup JobQueue
  32. * @since 1.33
  33. */
  34. interface RunnableJob extends IJobSpecification {
  35. /** @var int Job must not be wrapped in the usual explicit LBFactory transaction round */
  36. const JOB_NO_EXPLICIT_TRX_ROUND = 1;
  37. /**
  38. * Run the job
  39. * @return bool Success
  40. */
  41. public function run();
  42. /**
  43. * @param string|null $field Metadata field or null to get all the metadata
  44. * @return mixed|null Value; null if missing
  45. */
  46. public function getMetadata( $field = null );
  47. /**
  48. * @param string $field Key name to set the value for
  49. * @param mixed $value The value to set the field for
  50. * @return mixed|null The prior field value; null if missing
  51. */
  52. public function setMetadata( $field, $value );
  53. /**
  54. * @param int $flag JOB_* class constant
  55. * @return bool
  56. * @since 1.31
  57. */
  58. public function hasExecutionFlag( $flag );
  59. /**
  60. * @return string|null Id of the request that created this job. Follows
  61. * jobs recursively, allowing to track the id of the request that started a
  62. * job when jobs insert jobs which insert other jobs.
  63. * @since 1.27
  64. */
  65. public function getRequestId();
  66. /**
  67. * @return bool Whether this job can be retried on failure by job runners
  68. * @since 1.21
  69. */
  70. public function allowRetries();
  71. /**
  72. * @return int Number of actually "work items" handled in this job
  73. * @see $wgJobBackoffThrottling
  74. * @since 1.23
  75. */
  76. public function workItemCount();
  77. /**
  78. * @return int|null UNIX timestamp of when the job was runnable, or null
  79. * @since 1.26
  80. */
  81. public function getReadyTimestamp();
  82. /**
  83. * Do any final cleanup after run(), deferred updates, and all DB commits happen
  84. * @param bool $status Whether the job, its deferred updates, and DB commit all succeeded
  85. * @since 1.27
  86. */
  87. public function tearDown( $status );
  88. /**
  89. * @return string
  90. */
  91. public function getLastError();
  92. /**
  93. * @return string Debugging string describing the job
  94. */
  95. public function toString();
  96. }