Merge "Make sure that SQLite uses no prefix"
[lhc/web/wiklou.git] / includes / job / JobQueueDB.php
index d7d2b19..223ef41 100644 (file)
  * Class to handle job queues stored in the DB
  *
  * @ingroup JobQueue
- * @since 1.20
+ * @since 1.21
  */
 class JobQueueDB extends JobQueue {
-       const CACHE_TTL      = 30; // integer; seconds
+       const CACHE_TTL      = 300; // integer; seconds
        const MAX_JOB_RANDOM = 2147483647; // 2^31 - 1; used for job_random
 
        /**
@@ -97,7 +97,7 @@ class JobQueueDB extends JobQueue {
                                        $dbw->setFlag( $autoTrx ? DBO_TRX : 0 ); // restore automatic begin()
                                }
 
-                               $wgMemc->set( $key, 'false', $ttl );
+                               $wgMemc->set( $key, 'false', $ttl ); // queue is not empty
                        } );
                }
 
@@ -144,6 +144,7 @@ class JobQueueDB extends JobQueue {
                                $title = Title::makeTitleSafe( $row->job_namespace, $row->job_title );
                                if ( !$title ) {
                                        $dbw->delete( 'job', array( 'job_id' => $row->job_id ), __METHOD__ );
+                                       wfIncrStats( 'job-pop' );
                                        wfDebugLog( 'JobQueueDB', "Row has invalid title '{$row->job_title}'." );
                                        continue; // try again
                                }
@@ -156,6 +157,7 @@ class JobQueueDB extends JobQueue {
                                                        "job_id != {$dbw->addQuotes( $row->job_id )}" ),
                                                __METHOD__
                                        );
+                                       wfIncrStats( 'job-pop', $dbw->affectedRows() );
                                }
                                break; // done
                        } while( true );
@@ -277,10 +279,7 @@ class JobQueueDB extends JobQueue {
         */
        protected function doAck( Job $job ) {
                $dbw = $this->getMasterDB();
-               if ( $dbw->trxLevel() ) {
-                       wfWarn( "Attempted to ack a job in a transaction; committing first." );
-                       $dbw->commit(); // push existing transaction
-               }
+               $dbw->commit( __METHOD__, 'flush' ); // flush existing transaction
 
                $autoTrx = $dbw->getFlag( DBO_TRX ); // automatic begin() enabled?
                $dbw->clearFlag( DBO_TRX ); // make each query its own transaction
@@ -341,7 +340,7 @@ class JobQueueDB extends JobQueue {
                        'job_id'        => $dbw->nextSequenceValue( 'job_job_id_seq' ),
                        'job_timestamp' => $dbw->timestamp(),
                        'job_sha1'      => wfBaseConvert( sha1( serialize( $descFields ) ), 16, 36, 32 ),
-                       'job_random'    => mt_rand( 0, self::MAX_JOB_RANDOM )
+                       'job_random'    => $random
                );
                return ( $descFields + $metaFields );
        }