Have ApiRunJobs run periodic tasks
authorNik Everett <neverett@wikimedia.org>
Fri, 7 Mar 2014 15:39:21 +0000 (10:39 -0500)
committerNik Everett <neverett@wikimedia.org>
Fri, 7 Mar 2014 15:40:38 +0000 (10:40 -0500)
Without this apirunjobs can't handle delayed jobs.

Small inline comment updates as well.

Change-Id: I85ba0ac99eaebc16eaa7e2eb7019546241f3149c

includes/Wiki.php
includes/api/ApiRunJobs.php

index 5c67e5f..d78d7cb 100644 (file)
@@ -644,7 +644,8 @@ class MediaWiki {
                $query['signature'] = ApiRunJobs::getQuerySignature( $query );
 
                if ( !$wgEnableAPI ) {
-                       ApiRunJobs::executeJobs( $n ); // slow fallback
+                       // Fall back to running the job here while the user waits
+                       ApiRunJobs::executeJobs( $n );
                        return;
                }
 
@@ -660,7 +661,8 @@ class MediaWiki {
                wfRestoreWarnings();
                if ( !$sock ) {
                        wfDebugLog( 'runJobs', "Failed to start cron API (socket error $errno): $errstr\n" );
-                       ApiRunJobs::executeJobs( $n ); // slow fallback
+                       // Fall back to running the job here while the user waits
+                       ApiRunJobs::executeJobs( $n );
                        return;
                }
 
index e16dc5d..e23aaf5 100644 (file)
@@ -94,10 +94,14 @@ class ApiRunJobs extends ApiBase {
                        return;
                }
                try {
-                       // Fallback to running the jobs here while the user waits
                        $group = JobQueueGroup::singleton();
+                       $count = $group->executeReadyPeriodicTasks();
+                       if ( $count > 0 ) {
+                               wfDebugLog( 'jobqueue', "Executed $count periodic queue task(s)." );
+                       }
+
                        do {
-                               $job = $group->pop( JobQueueGroup::USE_CACHE ); // job from any queue
+                               $job = $group->pop( JobQueueGroup::TYPE_DEFAULT, JobQueueGroup::USE_CACHE ); // job from any queue
                                if ( $job ) {
                                        $output = $job->toString() . "\n";
                                        $t = - microtime( true );