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