r73198 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73197‎ | r73198 | r73199 >
Date:08:10, 17 September 2010
Author:nikerabbit
Status:reverted (Comments)
Tags:
Comment:
Add exclusive option for runJobs.php
Modified paths:
  • /trunk/phase3/maintenance/runJobs.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/runJobs.php
@@ -2,10 +2,6 @@
33 /**
44 * This script starts pending jobs.
55 *
6 - * Usage:
7 - * --maxjobs <num> (default 10000)
8 - * --type <job_cmd>
9 - *
106 * This program is free software; you can redistribute it and/or modify
117 * it under the terms of the GNU General Public License as published by
128 * the Free Software Foundation; either version 2 of the License, or
@@ -33,6 +29,7 @@
3430 $this->addOption( 'maxjobs', 'Maximum number of jobs to run', false, true );
3531 $this->addOption( 'type', 'Type of job to run', false, true );
3632 $this->addOption( 'procs', 'Number of processes to use', false, true );
 33+ $this->addOption( 'exclusive', 'Run only one exclusive runJobs script at a time. Timeout is 1800 seconds. Useful for cron scripts.', false );
3734 }
3835
3936 public function memoryLimit() {
@@ -41,6 +38,10 @@
4239 }
4340
4441 public function execute() {
 42+ if ( $this->lock() === false ) {
 43+ exit( 0 );
 44+ }
 45+
4546 global $wgTitle;
4647 if ( $this->hasOption( 'procs' ) ) {
4748 $procs = intval( $this->getOption( 'procs' ) );
@@ -49,6 +50,7 @@
5051 }
5152 $fc = new ForkController( $procs );
5253 if ( $fc->start( $procs ) != 'child' ) {
 54+ $this->unlock();
5355 exit( 0 );
5456 }
5557 }
@@ -85,6 +87,9 @@
8688 }
8789 }
8890 }
 91+ if ( !$this->hasOption( 'procs' ) ) {
 92+ $this->unlock();
 93+ }
8994 }
9095
9196 /**
@@ -95,6 +100,25 @@
96101 $this->output( wfTimestamp( TS_DB ) . " $msg\n" );
97102 wfDebugLog( 'runJobs', $msg );
98103 }
 104+
 105+ protected function lock() {
 106+ if ( $this->hasOption( 'exclusive' ) ) {
 107+ $cache = wfGetCache( CACHE_ANYTHING );
 108+ $running = $cache->get( wfMemcKey( 'runjobs' ) );
 109+ if ( $running ) {
 110+ return false;
 111+ } else {
 112+ $cache->set( wfMemcKey( 'runjobs' ), '1', 1800 );
 113+ return true;
 114+ }
 115+ }
 116+ return true;
 117+ }
 118+
 119+ protected function unlock() {
 120+ wfGetCache( CACHE_ANYTHING )->delete( wfMemcKey( 'runjobs' ) );
 121+ }
 122+
99123 }
100124
101125 $maintClass = "RunJobs";

Follow-up revisions

RevisionCommit summaryAuthorDate
r81519Revert r73198 (adding exclusing option to runJobs.php). Per CR, this should u...demon15:03, 4 February 2011

Comments

#Comment by Siebrand (talk | contribs)   08:18, 17 September 2010

Just so I get this... If a runJobs.php would crash, and a cache is available, this could cause no jobs to run for up to half an hour. Is that correct?

#Comment by Nikerabbit (talk | contribs)   08:21, 17 September 2010

Yes. Of course one can run runJobs.php manually and the processing during web requests if enabled also isn't affected.

#Comment by 😂 (talk | contribs)   20:42, 12 January 2011

I'm not really sure what purpose this is supposed to serve.

#Comment by Nikerabbit (talk | contribs)   20:48, 12 January 2011

"Useful for cron scripts", or otherwise you could end up with tens of simultaneous scripts.

#Comment by Platonides (talk | contribs)   23:08, 12 January 2011

You run it manually with --procs=2000. It errors out. You restart it with a better value, but it will now fail silently with no feedback for half an hour.

This should use a pool counter. The dummy default can be equivalent to this, but the user should be able to plug a better one.

#Comment by Nikerabbit (talk | contribs)   14:39, 23 January 2011

Is there docs on how to use pool counter?

#Comment by Platonides (talk | contribs)   15:20, 23 January 2011

Good point. I don't think they are really documented.

#Comment by Nikerabbit (talk | contribs)   21:13, 2 February 2011

Doesn't block deployment as far as I can see.

Status & tagging log