Merge "(Bug 41352) Provide tests for edit conflicts."
[lhc/web/wiklou.git] / includes / job / jobs / NullJob.php
1 <?php
2 /**
3 * Degenerate job that just replaces itself in the queue.
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 Cache
22 */
23
24 /**
25 * Degenerate job that just replace itself in the queue.
26 * Useful for lock contention and performance testing.
27 *
28 * @ingroup JobQueue
29 */
30 class NullJob extends Job {
31 /**
32 * @param $title Title (can be anything)
33 * @param $params Array: job parameters (lives, usleep)
34 * @param $id Integer: job id
35 */
36 function __construct( $title, $params, $id = 0 ) {
37 parent::__construct( 'null', $title, $params, $id );
38 if ( !isset( $this->params['lives'] ) ) {
39 $this->params['lives'] = 1;
40 }
41 if ( !isset( $this->params['usleep'] ) ) {
42 $this->params['usleep'] = 0;
43 }
44 }
45
46 public function run() {
47 if ( $this->params['usleep'] > 0 ) {
48 usleep( $this->params['usleep'] );
49 }
50 if ( $this->params['lives'] > 1 ) {
51 $params = $this->params;
52 $params['lives']--;
53 $job = new self( $this->title, $params );
54 $job->insert();
55 }
56 return true;
57 }
58 }