Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 1
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21namespace MediaWiki\JobQueue;
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 * calling their run() method. When constructing a job to be enqueued via JobQueue::push(), it
28 * 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 * See [the architecture doc](@ref jobqueuearch) for more information.
33 *
34 * @stable to implement
35 * @since 1.33
36 * @ingroup JobQueue
37 */
38interface RunnableJob extends IJobSpecification {
39    /** @var int Job must not be wrapped in the usual explicit LBFactory transaction round */
40    public const JOB_NO_EXPLICIT_TRX_ROUND = 1;
41
42    /**
43     * Run the job.
44     *
45     * If this method returns `false` or completes exceptionally, the job runner will retry executing this
46     * job unless the number of retries has exceeded its configured retry limit.
47     * Retries are allowed by default, unless allowRetries() is overridden to disable retries.
48     *
49     * See [the architecture doc](@ref jobqueuearch) for more information.
50     *
51     * @return bool Return `false` to instruct the job runner to retry a failed job.
52     * Otherwise return `true` to indicate that a job completed
53     * (i.e. succeeded, or failed in a way that's deterministic or redundant).
54     */
55    public function run();
56
57    /**
58     * @param string|null $field Metadata field or null to get all the metadata
59     * @return mixed|null Value; null if missing
60     */
61    public function getMetadata( $field = null );
62
63    /**
64     * @param string $field Key name to set the value for
65     * @param mixed $value The value to set the field for
66     * @return mixed|null The prior field value; null if missing
67     */
68    public function setMetadata( $field, $value );
69
70    /**
71     * @param int $flag JOB_* class constant
72     * @return bool
73     * @since 1.31
74     */
75    public function hasExecutionFlag( $flag );
76
77    /**
78     * @return string|null Id of the request that created this job. Follows
79     *  jobs recursively, allowing to track the id of the request that started a
80     *  job when jobs insert jobs which insert other jobs.
81     * @since 1.27
82     */
83    public function getRequestId();
84
85    /**
86     * Whether to retry execution of this job if run() returned `false` or threw an exception.
87     *
88     * @warning In some setups (i.e. when using change-propagation) jobs may
89     *  still be retried even when this is false if the job fails due to a
90     *  timeout unless it is also configured in change-prop config (T358939).
91     * @return bool Whether this job can be retried on failure by job runners
92     * @since 1.21
93     */
94    public function allowRetries();
95
96    /**
97     * @return int Number of actually "work items" handled in this job
98     * @see $wgJobBackoffThrottling
99     * @since 1.23
100     */
101    public function workItemCount();
102
103    /**
104     * @return int|null UNIX timestamp of when the job was runnable, or null
105     * @since 1.26
106     */
107    public function getReadyTimestamp();
108
109    /**
110     * Do any final cleanup after run(), deferred updates, and all DB commits happen
111     * @param bool $status Whether the job, its deferred updates, and DB commit all succeeded
112     * @since 1.27
113     */
114    public function tearDown( $status );
115
116    /**
117     * @return string
118     */
119    public function getLastError();
120
121    /**
122     * @return string Debugging string describing the job
123     */
124    public function toString();
125}
126
127/** @deprecated class alias since 1.44 */
128class_alias( RunnableJob::class, 'RunnableJob' );