From: daniel Date: Fri, 6 Sep 2019 16:40:07 +0000 (+0200) Subject: SpecialRunJobs: optional output stats and status. X-Git-Tag: 1.34.0-rc.0~267^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/membres/fiche.php?a=commitdiff_plain;h=c28609ac617d8fc4987338955003fe2c6b687a54;p=lhc%2Fweb%2Fwiklou.git SpecialRunJobs: optional output stats and status. This adds a parameter to SpecialRunJobs that lets it output statistics about the jobs it has run. The 'reached' field can be used to detect when the queue is emopty, which is essential to know for clients that want to flush the entire job queue, to ensure that all effects of any actions they have taken have been processed. More specifically, this provides a way for an external testing framework to run all jobs after an action, so it can observe and assert the effects of that action. Bug: T231822 Change-Id: Ibb38490afca71efeb67300b9665951c429c19a3c --- diff --git a/includes/specials/SpecialRunJobs.php b/includes/specials/SpecialRunJobs.php index 375694be08..530c5802cf 100644 --- a/includes/specials/SpecialRunJobs.php +++ b/includes/specials/SpecialRunJobs.php @@ -52,7 +52,8 @@ class SpecialRunJobs extends UnlistedSpecialPage { } // Validate request parameters - $optional = [ 'maxjobs' => 0, 'maxtime' => 30, 'type' => false, 'async' => true ]; + $optional = [ 'maxjobs' => 0, 'maxtime' => 30, 'type' => false, + 'async' => true, 'stats' => false ]; $required = array_flip( [ 'title', 'tasks', 'signature', 'sigexpiry' ] ); $params = array_intersect_key( $this->getRequest()->getValues(), $required + $optional ); $missing = array_diff_key( $required, $params ); @@ -95,14 +96,20 @@ class SpecialRunJobs extends UnlistedSpecialPage { DeferredUpdates::POSTSEND ); } else { - $this->doRun( $params ); - print "Done\n"; + $stats = $this->doRun( $params ); + + if ( $params['stats'] ) { + $this->getRequest()->response()->header( 'Content-Type: application/json' ); + print FormatJson::encode( $stats ); + } else { + print "Done\n"; + } } } protected function doRun( array $params ) { $runner = new JobRunner( LoggerFactory::getInstance( 'runJobs' ) ); - $runner->run( [ + return $runner->run( [ 'type' => $params['type'], 'maxJobs' => $params['maxjobs'] ?: 1, 'maxTime' => $params['maxtime'] ?: 30