Merge "Don't fallback from uk to ru"
[lhc/web/wiklou.git] / includes / jobqueue / JobQueueRedis.php
index d4a5334..25a271c 100644 (file)
@@ -20,6 +20,7 @@
  * @file
  * @author Aaron Schulz
  */
+use Psr\Log\LoggerInterface;
 
 /**
  * Class to handle job queues stored in Redis
 class JobQueueRedis extends JobQueue {
        /** @var RedisConnectionPool */
        protected $redisPool;
+       /** @var LoggerInterface */
+       protected $logger;
 
        /** @var string Server address */
        protected $server;
        /** @var string Compression method to use */
        protected $compression;
 
-       const MAX_AGE_PRUNE = 604800; // integer; seconds a job can live once claimed (7 days)
-
-       /** @var string Key to prefix the queue keys with (used for testing) */
-       protected $key;
-
        /**
         * @param array $params Possible keys:
         *   - redisConfig : An array of parameters to RedisConnectionPool::__construct().
@@ -101,6 +99,7 @@ class JobQueueRedis extends JobQueue {
                                "Non-daemonized mode is no longer supported. Please install the " .
                                "mediawiki/services/jobrunner service and update \$wgJobTypeConf as needed." );
                }
+               $this->logger = \MediaWiki\Logger\LoggerFactory::getInstance( 'redis' );
        }
 
        protected function supportedOrders() {
@@ -255,6 +254,7 @@ class JobQueueRedis extends JobQueue {
                        $args[] = (string)$this->serialize( $item );
                }
                static $script =
+               /** @lang Lua */
 <<<LUA
                local kUnclaimed, kSha1ById, kIdBySha1, kDelayed, kData, kQwJobs = unpack(KEYS)
                -- First argument is the queue ID
@@ -344,6 +344,7 @@ LUA;
         */
        protected function popAndAcquireBlob( RedisConnRef $conn ) {
                static $script =
+               /** @lang Lua */
 <<<LUA
                local kUnclaimed, kSha1ById, kIdBySha1, kClaimed, kAttempts, kData = unpack(KEYS)
                local rTime = unpack(ARGV)
@@ -391,14 +392,20 @@ LUA;
                $conn = $this->getConnection();
                try {
                        static $script =
+                       /** @lang Lua */
 <<<LUA
                        local kClaimed, kAttempts, kData = unpack(KEYS)
-                       local uuid = unpack(ARGV)
+                       local id = unpack(ARGV)
                        -- Unmark the job as claimed
-                       redis.call('zRem',kClaimed,uuid)
-                       redis.call('hDel',kAttempts,uuid)
+                       local removed = redis.call('zRem',kClaimed,id)
+                       -- Check if the job was recycled
+                       if removed == 0 then
+                               return 0
+                       end
+                       -- Delete the retry data
+                       redis.call('hDel',kAttempts,id)
                        -- Delete the job data itself
-                       return redis.call('hDel',kData,uuid)
+                       return redis.call('hDel',kData,id)
 LUA;
                        $res = $conn->luaEval( $script,
                                [
@@ -745,7 +752,7 @@ LUA;
         * @throws JobQueueConnectionError
         */
        protected function getConnection() {
-               $conn = $this->redisPool->getConnection( $this->server );
+               $conn = $this->redisPool->getConnection( $this->server, $this->logger );
                if ( !$conn ) {
                        throw new JobQueueConnectionError(
                                "Unable to connect to redis server {$this->server}." );