Enable DBO_TRX for runJobs.php, just like HTTP job runner
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 21 Apr 2015 23:28:49 +0000 (16:28 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 22 Apr 2015 00:42:31 +0000 (17:42 -0700)
Change-Id: Ic6fa2f9f0d18aeeb15f482e2faab2ebc56650570

maintenance/runJobs.php

index c8445da..3c5d28b 100644 (file)
@@ -52,6 +52,8 @@ class RunJobs extends Maintenance {
        }
 
        public function execute() {
+               global $wgCommandLineMode;
+
                if ( $this->hasOption( 'procs' ) ) {
                        $procs = intval( $this->getOption( 'procs' ) );
                        if ( $procs < 1 || $procs > 1000 ) {
@@ -64,21 +66,29 @@ class RunJobs extends Maintenance {
                        }
                }
 
-               $json = ( $this->getOption( 'result' ) === 'json' );
+               $outputJSON = ( $this->getOption( 'result' ) === 'json' );
+
+               // Enable DBO_TRX for atomicity; JobRunner manages transactions
+               // and works well in web server mode already (@TODO: this is a hack)
+               $wgCommandLineMode = false;
 
                $runner = new JobRunner( LoggerFactory::getInstance( 'runJobs' ) );
-               if ( !$json ) {
+               if ( !$outputJSON ) {
                        $runner->setDebugHandler( array( $this, 'debugInternal' ) );
                }
+
                $response = $runner->run( array(
                        'type'     => $this->getOption( 'type', false ),
                        'maxJobs'  => $this->getOption( 'maxjobs', false ),
                        'maxTime'  => $this->getOption( 'maxtime', false ),
                        'throttle' => $this->hasOption( 'nothrottle' ) ? false : true,
                ) );
-               if ( $json ) {
+
+               if ( $outputJSON ) {
                        $this->output( FormatJson::encode( $response, true ) );
                }
+
+               $wgCommandLineMode = true;
        }
 
        /**