Follow-up f7cddcf7c1: Move RELEASE-NOTES-1.34 entry to right place
[lhc/web/wiklou.git] / maintenance / runJobs.php
index 2e011fe..9354e4f 100644 (file)
  * @ingroup Maintenance
  */
 
+if ( !defined( 'MEDIAWIKI' ) ) {
+       // So extensions (and other code) can check whether they're running in job mode.
+       // This is not defined if this script is included from installer/updater or phpunit.
+       define( 'MEDIAWIKI_JOB_RUNNER', true );
+}
+
 require_once __DIR__ . '/Maintenance.php';
 
 use MediaWiki\Logger\LoggerFactory;
@@ -39,7 +45,7 @@ class RunJobs extends Maintenance {
                $this->addOption( 'type', 'Type of job to run', false, true );
                $this->addOption( 'procs', 'Number of processes to use', false, true );
                $this->addOption( 'nothrottle', 'Ignore job throttling configuration', false, false );
-               $this->addOption( 'result', 'Set to JSON to print only a JSON response', false, true );
+               $this->addOption( 'result', 'Set to "json" to print only a JSON response', false, true );
                $this->addOption( 'wait', 'Wait for new jobs instead of exiting', false, false );
        }
 
@@ -56,7 +62,7 @@ class RunJobs extends Maintenance {
                if ( $this->hasOption( 'procs' ) ) {
                        $procs = intval( $this->getOption( 'procs' ) );
                        if ( $procs < 1 || $procs > 1000 ) {
-                               $this->error( "Invalid argument to --procs", true );
+                               $this->fatalError( "Invalid argument to --procs" );
                        } elseif ( $procs != 1 ) {
                                $fc = new ForkController( $procs );
                                if ( $fc->start() != 'child' ) {
@@ -96,6 +102,10 @@ class RunJobs extends Maintenance {
                                $response['reached'] === 'job-limit' ||
                                $response['reached'] === 'memory-limit'
                        ) {
+                               // If job queue is empty, output it
+                               if ( !$outputJSON && $response['jobs'] === [] ) {
+                                       $this->output( "Job queue is empty.\n" );
+                               }
                                break;
                        }
 
@@ -115,5 +125,5 @@ class RunJobs extends Maintenance {
        }
 }
 
-$maintClass = "RunJobs";
+$maintClass = RunJobs::class;
 require_once RUN_MAINTENANCE_IF_MAIN;