3 * Degenerate job that does nothing.
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.
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.
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
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.
30 * Inserting a null job in the configured job queue:
32 * $ php maintenance/eval.php
33 * > $queue = JobQueueGroup::singleton();
34 * > $job = new NullJob( Title::newMainPage(), array( 'lives' => 10 ) );
35 * > $queue->push( $job );
37 * You can then confirm the job has been enqueued by using the showJobs.php
38 * maintenance utility:
40 * $ php maintenance/showJobs.php --group
41 * null: 1 queue; 0 claimed (0 active, 0 abandoned)
47 class NullJob
extends Job
{
50 * @param array $params Job parameters (lives, usleep)
52 function __construct( $title, $params ) {
53 parent
::__construct( 'null', $title, $params );
54 if ( !isset( $this->params
['lives'] ) ) {
55 $this->params
['lives'] = 1;
57 if ( !isset( $this->params
['usleep'] ) ) {
58 $this->params
['usleep'] = 0;
60 $this->removeDuplicates
= !empty( $this->params
['removeDuplicates'] );
63 public function run() {
64 if ( $this->params
['usleep'] > 0 ) {
65 usleep( $this->params
['usleep'] );
67 if ( $this->params
['lives'] > 1 ) {
68 $params = $this->params
;
70 $job = new self( $this->title
, $params );
71 JobQueueGroup
::singleton()->push( $job );