// Actually do the work of the request and build up any output
$this->performRequest();
+ // Either all DB and deferred updates should happen or none.
+ // The later should not be cancelled due to client disconnect.
+ ignore_user_abort( true );
// Now commit any transactions, so that unreported errors after
// output() don't roll back the whole DB transaction
wfGetLBFactory()->commitMasterChanges();
* the socket once it's done.
*/
protected function triggerJobs() {
- global $wgJobRunRate, $wgServer, $wgScriptPath, $wgScriptExtension, $wgEnableAPI;
+ global $wgJobRunRate, $wgServer;
if ( $wgJobRunRate <= 0 || wfReadOnly() ) {
return;
+ } elseif ( $this->getTitle()->isSpecial( 'RunJobs' ) ) {
+ return; // recursion guard
}
$section = new ProfileSection( __METHOD__ );
$n = intval( $wgJobRunRate );
}
- $query = array( 'action' => 'runjobs',
+ $query = array( 'title' => 'Special:RunJobs',
'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();
- return;
- }
+ $query['signature'] = SpecialRunJobs::getQuerySignature( $query );
$errno = $errstr = null;
$info = wfParseUrl( $wgServer );
$info['host'],
isset( $info['port'] ) ? $info['port'] : 80,
$errno,
- $errstr
+ $errstr,
+ // If it takes more than 100ms to connect to ourselves there
+ // is a problem elsewhere.
+ 0.1
);
wfRestoreWarnings();
if ( !$sock ) {
wfDebugLog( 'runJobs', "Failed to start cron API (socket error $errno): $errstr\n" );
- $fallback();
+ // Fall back to running the job here while the user waits
+ SpecialRunJobs::executeJobs( $n );
return;
}
- $url = wfAppendQuery( "{$wgScriptPath}/api{$wgScriptExtension}", $query );
+ $url = wfAppendQuery( wfScript( 'index' ), $query );
$req = "POST $url HTTP/1.1\r\nHost: {$info['host']}\r\nConnection: Close\r\n\r\n";
wfDebugLog( 'runJobs', "Running $n job(s) via '$url'\n" );
// 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" );
}
}