3 * This script starts pending jobs.
6 * --maxjobs <num> (default 10000)
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
24 * @ingroup Maintenance
27 require_once( dirname(__FILE__
) . '/Maintenance.php' );
29 class RunJobs
extends Maintenance
{
30 public function __construct() {
31 global $wgUseNormalUser;
32 parent
::__construct();
33 $this->mDescription
= "Run pending jobs";
34 $this->addOption( 'maxjobs', 'Maximum number of jobs to run', false, true );
35 $this->addOption( 'type', 'Type of job to run', false, true );
36 $this->addOption( 'procs', 'Number of processes to use', false, true );
37 $wgUseNormalUser = true;
40 public function execute() {
42 if ( $this->hasOption( 'procs' ) ) {
43 $procs = intval( $this->getOption('procs') );
44 if ( $procs < 1 ||
$procs > 1000 ) {
45 $this->error( "Invalid argument to --procs", true );
47 $fc = new ForkController( $procs );
48 if ( $fc->start( $procs ) != 'child' ) {
52 $maxJobs = $this->getOption( 'maxjobs', 10000 );
53 $type = $this->getOption( 'type', false );
54 $wgTitle = Title
::newFromText( 'RunJobs.php' );
55 $dbw = wfGetDB( DB_MASTER
);
59 $conds = "job_cmd = " . $dbw->addQuotes($type);
61 while ( $dbw->selectField( 'job', 'job_id', $conds, 'runJobs.php' ) ) {
64 $job = ($type == false) ?
66 : Job
::pop_type($type);
72 $t = microtime( true );
74 $status = $job->run();
75 $t = microtime( true ) - $t;
76 $timeMs = intval( $t * 1000 );
78 $this->runJobsLog( $job->toString() . " t=$timeMs error={$job->error}" );
80 $this->runJobsLog( $job->toString() . " t=$timeMs good" );
82 if ( $maxJobs && ++
$n > $maxJobs ) {
91 * @param $msg String The message to log
93 private function runJobsLog( $msg ) {
94 $this->output( wfTimestamp( TS_DB
) . " $msg\n" );
95 wfDebugLog( 'runJobs', $msg );
99 $maintClass = "RunJobs";
100 require_once( DO_MAINTENANCE
);