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 parent
::__construct();
32 $this->mDescription
= "Run pending jobs";
33 $this->addOption( 'maxjobs', 'Maximum number of jobs to run', false, true );
34 $this->addOption( 'maxtime', 'Maximum amount of wall-clock time', false, true );
35 $this->addOption( 'type', 'Type of job to run', false, true );
36 $this->addOption( 'procs', 'Number of processes to use', false, true );
39 public function memoryLimit() {
40 if ( $this->hasOption( 'memory-limit' ) ) {
41 return parent
::memoryLimit();
43 // Don't eat all memory on the machine if we get a bad job.
47 public function execute() {
49 if ( $this->hasOption( 'procs' ) ) {
50 $procs = intval( $this->getOption( 'procs' ) );
51 if ( $procs < 1 ||
$procs > 1000 ) {
52 $this->error( "Invalid argument to --procs", true );
54 $fc = new ForkController( $procs );
55 if ( $fc->start() != 'child' ) {
59 $maxJobs = $this->getOption( 'maxjobs', false );
60 $maxTime = $this->getOption( 'maxtime', false );
62 $type = $this->getOption( 'type', false );
63 $wgTitle = Title
::newFromText( 'RunJobs.php' );
64 $dbw = wfGetDB( DB_MASTER
);
67 if ( $type === false ) {
68 $conds = Job
::defaultQueueConditions( );
70 $conds = array( 'job_cmd' => $type );
73 while ( $dbw->selectField( 'job', 'job_id', $conds, 'runJobs.php' ) ) {
76 $job = !$type ? Job
::pop( $offset ) : Job
::pop_type( $type );
83 $t = microtime( true );
85 $this->runJobsLog( $job->toString() . " STARTING" );
86 $status = $job->run();
87 $t = microtime( true ) - $t;
88 $timeMs = intval( $t * 1000 );
90 $this->runJobsLog( $job->toString() . " t=$timeMs error={$job->error}" );
92 $this->runJobsLog( $job->toString() . " t=$timeMs good" );
95 if ( $maxJobs && ++
$n > $maxJobs ) {
98 if ( $maxTime && time() - $startTime > $maxTime ) {
106 * Log the job message
107 * @param $msg String The message to log
109 private function runJobsLog( $msg ) {
110 $this->output( wfTimestamp( TS_DB
) . " $msg\n" );
111 wfDebugLog( 'runJobs', $msg );
115 $maintClass = "RunJobs";
116 require_once( RUN_MAINTENANCE_IF_MAIN
);