Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
NullJob
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 2
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
 run
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
12
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\Jobs;
22
23use MediaWiki\JobQueue\GenericParameterJob;
24use MediaWiki\JobQueue\Job;
25use MediaWiki\MediaWikiServices;
26
27/**
28 * No-op job that does nothing.
29 *
30 * This is used for testing purposes, e.g. to measure overall system
31 * performance of the JobQueue system, lock contention, etc.
32 *
33 * This job can optionally recursively re-queue itself a number of times
34 * or spend a fixed amount of time idling in execution time.
35 *
36 * @par Example:
37 * Inserting a null job in the configured job queue:
38 * @code
39 * $ php maintenance/eval.php
40 * > $queue = MediaWikiServices::getInstance()->getJobQueueGroup();
41 * > $job = new NullJob( [ 'lives' => 10 ] );
42 * > $queue->push( $job );
43 * @endcode
44 *
45 * You can confirm the job has been enqueued via maintenance/showJobs.php:
46 *
47 * @code
48 * $ php maintenance/showJobs.php --group
49 * null: 1 queue; 0 claimed (0 active, 0 abandoned)
50 * @endcode
51 *
52 * @ingroup JobQueue
53 */
54class NullJob extends Job implements GenericParameterJob {
55    /**
56     * @param array $params Job parameters (lives, usleep)
57     */
58    public function __construct( array $params ) {
59        parent::__construct( 'null', $params );
60        if ( !isset( $this->params['lives'] ) ) {
61            $this->params['lives'] = 1;
62        }
63        if ( !isset( $this->params['usleep'] ) ) {
64            $this->params['usleep'] = 0;
65        }
66        $this->removeDuplicates = !empty( $this->params['removeDuplicates'] );
67    }
68
69    public function run() {
70        if ( $this->params['usleep'] > 0 ) {
71            usleep( $this->params['usleep'] );
72        }
73        if ( $this->params['lives'] > 1 ) {
74            $params = $this->params;
75            $params['lives']--;
76            $job = new self( $params );
77            MediaWikiServices::getInstance()->getJobQueueGroup()->push( $job );
78        }
79
80        return true;
81    }
82}
83
84/** @deprecated class alias since 1.44 */
85class_alias( NullJob::class, 'NullJob' );