Merge "Type hint against LinkTarget in WatchedItemStore"
[lhc/web/wiklou.git] / includes / jobqueue / RunnableJob.php
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 /**
24 * Job that has a run() method and metadata accessors for JobQueue::pop() and JobQueue::ack()
25 *
26 * Instances are not only enqueueable via JobQueue::push(), but they can also be executed by
27 * by calling their run() method. When constructing a job to be enqueued via JobQueue::push(),
28 * it will not be possible to construct a RunnableJob instance if the class for that job is not
29 * loaded by the application for the local DB domain. In that case, the general-purpose
30 * JobSpecification class can be used instead.
31 *
32 * @ingroup JobQueue
33 * @since 1.33
34 */
35 interface RunnableJob extends IJobSpecification {
36 /** @var int Job must not be wrapped in the usual explicit LBFactory transaction round */
37 const JOB_NO_EXPLICIT_TRX_ROUND = 1;
38
39 /**
40 * Run the job
41 * @return bool Success
42 */
43 public function run();
44
45 /**
46 * @param string|null $field Metadata field or null to get all the metadata
47 * @return mixed|null Value; null if missing
48 */
49 public function getMetadata( $field = null );
50
51 /**
52 * @param string $field Key name to set the value for
53 * @param mixed $value The value to set the field for
54 * @return mixed|null The prior field value; null if missing
55 */
56 public function setMetadata( $field, $value );
57
58 /**
59 * @param int $flag JOB_* class constant
60 * @return bool
61 * @since 1.31
62 */
63 public function hasExecutionFlag( $flag );
64
65 /**
66 * @return string|null Id of the request that created this job. Follows
67 * jobs recursively, allowing to track the id of the request that started a
68 * job when jobs insert jobs which insert other jobs.
69 * @since 1.27
70 */
71 public function getRequestId();
72
73 /**
74 * @return bool Whether this job can be retried on failure by job runners
75 * @since 1.21
76 */
77 public function allowRetries();
78
79 /**
80 * @return int Number of actually "work items" handled in this job
81 * @see $wgJobBackoffThrottling
82 * @since 1.23
83 */
84 public function workItemCount();
85
86 /**
87 * @return int|null UNIX timestamp of when the job was runnable, or null
88 * @since 1.26
89 */
90 public function getReadyTimestamp();
91
92 /**
93 * Do any final cleanup after run(), deferred updates, and all DB commits happen
94 * @param bool $status Whether the job, its deferred updates, and DB commit all succeeded
95 * @since 1.27
96 */
97 public function tearDown( $status );
98
99 /**
100 * @return string
101 */
102 public function getLastError();
103
104 /**
105 * @return string Debugging string describing the job
106 */
107 public function toString();
108 }