Merge "Don't fallback from uk to ru"
[lhc/web/wiklou.git] / includes / jobqueue / jobs / NullJob.php
1 <?php
2 /**
3 * Degenerate job that does nothing.
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 * @ingroup JobQueue
22 */
23
24 /**
25 * Degenerate job that does nothing, but can optionally replace itself
26 * in the queue and/or sleep for a brief time period. These can be used
27 * to represent "no-op" jobs or test lock contention and performance.
28 *
29 * @par Example:
30 * Inserting a null job in the configured job queue:
31 * @code
32 * $ php maintenance/eval.php
33 * > $queue = JobQueueGroup::singleton();
34 * > $job = new NullJob( Title::newMainPage(), [ 'lives' => 10 ] );
35 * > $queue->push( $job );
36 * @endcode
37 * You can then confirm the job has been enqueued by using the showJobs.php
38 * maintenance utility:
39 * @code
40 * $ php maintenance/showJobs.php --group
41 * null: 1 queue; 0 claimed (0 active, 0 abandoned)
42 * $
43 * @endcode
44 *
45 * @ingroup JobQueue
46 */
47 class NullJob extends Job {
48 /**
49 * @param Title $title
50 * @param array $params Job parameters (lives, usleep)
51 */
52 function __construct( Title $title, array $params ) {
53 parent::__construct( 'null', $title, $params );
54 if ( !isset( $this->params['lives'] ) ) {
55 $this->params['lives'] = 1;
56 }
57 if ( !isset( $this->params['usleep'] ) ) {
58 $this->params['usleep'] = 0;
59 }
60 $this->removeDuplicates = !empty( $this->params['removeDuplicates'] );
61 }
62
63 public function run() {
64 if ( $this->params['usleep'] > 0 ) {
65 usleep( $this->params['usleep'] );
66 }
67 if ( $this->params['lives'] > 1 ) {
68 $params = $this->params;
69 $params['lives']--;
70 $job = new self( $this->title, $params );
71 JobQueueGroup::singleton()->push( $job );
72 }
73
74 return true;
75 }
76 }