Index: trunk/phase3/maintenance/runJobs.php |
— | — | @@ -2,10 +2,6 @@ |
3 | 3 | /** |
4 | 4 | * This script starts pending jobs. |
5 | 5 | * |
6 | | - * Usage: |
7 | | - * --maxjobs <num> (default 10000) |
8 | | - * --type <job_cmd> |
9 | | - * |
10 | 6 | * This program is free software; you can redistribute it and/or modify |
11 | 7 | * it under the terms of the GNU General Public License as published by |
12 | 8 | * the Free Software Foundation; either version 2 of the License, or |
— | — | @@ -33,6 +29,7 @@ |
34 | 30 | $this->addOption( 'maxjobs', 'Maximum number of jobs to run', false, true ); |
35 | 31 | $this->addOption( 'type', 'Type of job to run', false, true ); |
36 | 32 | $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 ); |
37 | 34 | } |
38 | 35 | |
39 | 36 | public function memoryLimit() { |
— | — | @@ -41,6 +38,10 @@ |
42 | 39 | } |
43 | 40 | |
44 | 41 | public function execute() { |
| 42 | + if ( $this->lock() === false ) { |
| 43 | + exit( 0 ); |
| 44 | + } |
| 45 | + |
45 | 46 | global $wgTitle; |
46 | 47 | if ( $this->hasOption( 'procs' ) ) { |
47 | 48 | $procs = intval( $this->getOption( 'procs' ) ); |
— | — | @@ -49,6 +50,7 @@ |
50 | 51 | } |
51 | 52 | $fc = new ForkController( $procs ); |
52 | 53 | if ( $fc->start( $procs ) != 'child' ) { |
| 54 | + $this->unlock(); |
53 | 55 | exit( 0 ); |
54 | 56 | } |
55 | 57 | } |
— | — | @@ -85,6 +87,9 @@ |
86 | 88 | } |
87 | 89 | } |
88 | 90 | } |
| 91 | + if ( !$this->hasOption( 'procs' ) ) { |
| 92 | + $this->unlock(); |
| 93 | + } |
89 | 94 | } |
90 | 95 | |
91 | 96 | /** |
— | — | @@ -95,6 +100,25 @@ |
96 | 101 | $this->output( wfTimestamp( TS_DB ) . " $msg\n" ); |
97 | 102 | wfDebugLog( 'runJobs', $msg ); |
98 | 103 | } |
| 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 | + |
99 | 123 | } |
100 | 124 | |
101 | 125 | $maintClass = "RunJobs"; |