[JobQueue] Do not count claimed jobs in isEmpty().
[lhc/web/wiklou.git] / includes / job / JobQueueDB.php
index 3e057eb..4d0f294 100644 (file)
@@ -49,15 +49,19 @@ class JobQueueDB extends JobQueue {
                        return false;
                }
 
-               $found = $this->getSlaveDB()->selectField(
-                       'job', '1', array( 'job_cmd' => $this->type ), __METHOD__
+               $found = $this->getSlaveDB()->selectField( // unclaimed job
+                       'job', '1', array( 'job_cmd' => $this->type, 'job_token' => '' ), __METHOD__
                );
 
                $wgMemc->add( $key, $found ? 'false' : 'true', self::CACHE_TTL );
+               return (bool)$found;
        }
 
        /**
         * @see JobQueue::doBatchPush()
+        * @param array $jobs
+        * @param $flags
+        * @throws DBError|Exception
         * @return bool
         */
        protected function doBatchPush( array $jobs, $flags ) {
@@ -174,6 +178,7 @@ class JobQueueDB extends JobQueue {
                        }
                        $job = Job::factory( $row->job_cmd, $title,
                                self::extractBlob( $row->job_params ), $row->job_id );
+                       $job->id = $row->job_id; // XXX: work around broken subclasses
                        // Flag this job as an old duplicate based on its "root" job...
                        if ( $this->isRootJobOldDuplicate( $job ) ) {
                                $job = DuplicateJob::newFromJob( $job ); // convert to a no-op
@@ -365,20 +370,29 @@ class JobQueueDB extends JobQueue {
 
        /**
         * @see JobQueue::doAck()
+        * @param Job $job
+        * @throws MWException
         * @return Job|bool
         */
        protected function doAck( Job $job ) {
+               if ( !$job->getId() ) {
+                       throw new MWException( "Job of type '{$job->getType()}' has no ID." );
+               }
+
                $dbw = $this->getMasterDB();
                $dbw->commit( __METHOD__, 'flush' ); // flush existing transaction
 
                // Delete a row with a single DELETE without holding row locks over RTTs...
-               $dbw->delete( 'job', array( 'job_cmd' => $this->type, 'job_id' => $job->getId() ) );
+               $dbw->delete( 'job',
+                       array( 'job_cmd' => $this->type, 'job_id' => $job->getId() ), __METHOD__ );
 
                return true;
        }
 
        /**
         * @see JobQueue::doDeduplicateRootJob()
+        * @param Job $job
+        * @throws MWException
         * @return bool
         */
        protected function doDeduplicateRootJob( Job $job ) {