http://www.mediawiki.org/wiki/Special:Code/MediaWiki/73198
Revision: 73198
Author: nikerabbit
Date: 2010-09-17 08:10:38 +0000 (Fri, 17 Sep 2010)
Log Message:
-----------
Add exclusive option for runJobs.php
Modified Paths:
--------------
trunk/phase3/maintenance/runJobs.php
Modified: trunk/phase3/maintenance/runJobs.php
===================================================================
--- trunk/phase3/maintenance/runJobs.php 2010-09-17 08:04:18 UTC (rev
73197)
+++ trunk/phase3/maintenance/runJobs.php 2010-09-17 08:10:38 UTC (rev
73198)
@@ -2,10 +2,6 @@
/**
* This script starts pending jobs.
*
- * Usage:
- * --maxjobs <num> (default 10000)
- * --type <job_cmd>
- *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -33,6 +29,7 @@
$this->addOption( 'maxjobs', 'Maximum number of jobs to run',
false, true );
$this->addOption( 'type', 'Type of job to run', false, true );
$this->addOption( 'procs', 'Number of processes to use', false,
true );
+ $this->addOption( 'exclusive', 'Run only one exclusive runJobs
script at a time. Timeout is 1800 seconds. Useful for cron scripts.', false );
}
public function memoryLimit() {
@@ -41,6 +38,10 @@
}
public function execute() {
+ if ( $this->lock() === false ) {
+ exit( 0 );
+ }
+
global $wgTitle;
if ( $this->hasOption( 'procs' ) ) {
$procs = intval( $this->getOption( 'procs' ) );
@@ -49,6 +50,7 @@
}
$fc = new ForkController( $procs );
if ( $fc->start( $procs ) != 'child' ) {
+ $this->unlock();
exit( 0 );
}
}
@@ -85,6 +87,9 @@
}
}
}
+ if ( !$this->hasOption( 'procs' ) ) {
+ $this->unlock();
+ }
}
/**
@@ -95,6 +100,25 @@
$this->output( wfTimestamp( TS_DB ) . " $msg\n" );
wfDebugLog( 'runJobs', $msg );
}
+
+ protected function lock() {
+ if ( $this->hasOption( 'exclusive' ) ) {
+ $cache = wfGetCache( CACHE_ANYTHING );
+ $running = $cache->get( wfMemcKey( 'runjobs' ) );
+ if ( $running ) {
+ return false;
+ } else {
+ $cache->set( wfMemcKey( 'runjobs' ), '1', 1800
);
+ return true;
+ }
+ }
+ return true;
+ }
+
+ protected function unlock() {
+ wfGetCache( CACHE_ANYTHING )->delete( wfMemcKey( 'runjobs' ) );
+ }
+
}
$maintClass = "RunJobs";
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs