'tasks' => 'jobs', 'maxjobs' => $n, 'sigexpiry' => time() + 5 );
$query['signature'] = ApiRunJobs::getQuerySignature( $query );
- // Slow job running method in case of API or socket functions being disabled
- $fallback = function() use ( $query ) {
- $api = new ApiMain( new FauxRequest( $query, true ) );
- $api->execute();
- };
-
if ( !$wgEnableAPI ) {
- $fallback();
+ ApiRunJobs::executeJobs( $n ); // slow fallback
return;
}
wfRestoreWarnings();
if ( !$sock ) {
wfDebugLog( 'runJobs', "Failed to start cron API (socket error $errno): $errstr\n" );
- $fallback();
+ ApiRunJobs::executeJobs( $n ); // slow fallback
return;
}
// Do not wait for the response (the script should handle client aborts).
// Make sure that we don't close before that script reaches ignore_user_abort().
$status = fgets( $sock );
- if ( !preg_match( '#^HTTP/\d\.\d 204 #', $status ) ) {
+ if ( !preg_match( '#^HTTP/\d\.\d 202 #', $status ) ) {
wfDebugLog( 'runJobs', "Failed to start cron API: received '$status'\n" );
}
}
}
if ( !$verified || $params['sigexpiry'] < time() ) {
- $this->dieUsage( 'Invalid or stale signature provided', 'bad_signature', 401 );
+ $this->dieUsage( 'Invalid or stale signature provided', 'bad_signature', 400 );
}
// Client will usually disconnect before checking the response,
// but it needs to know when it is safe to disconnect. Until this
// reaches ignore_user_abort(), it is not safe as the jobs won't run.
ignore_user_abort( true ); // jobs may take a bit of time
- header( "HTTP/1.0 204 No Content" );
+ header( "HTTP/1.0 202 Accepted" );
ob_flush();
flush();
// Once the client receives this response, it can disconnect
// Do all of the specified tasks...
if ( in_array( 'jobs', $params['tasks'] ) ) {
- $this->executeJobs( $params );
+ self::executeJobs( $params['maxjobs'] );
}
}
/**
* Run jobs from the job queue
*
- * @param array $params Request parameters
+ * @note: also called from Wiki.php
+ *
+ * @param integer $maxJobs Maximum number of jobs to run
* @return void
*/
- protected function executeJobs( array $params ) {
- $n = $params['maxjobs']; // number of jobs to run
+ public static function executeJobs( $maxJobs ) {
+ $n = $maxJobs; // number of jobs to run
if ( $n < 1 ) {
return;
}