X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2Fjobqueue%2FJobQueueRedis.php;h=7dad014e45151c70d81b961c59ddae28932f476e;hb=4f31afd21b208965bae734396f6e2c6df06684c7;hp=a356e84c652e48a885419d57c2fd1f918306d789;hpb=7e90af0237ecc1809e1a664213536b97846df69c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/jobqueue/JobQueueRedis.php b/includes/jobqueue/JobQueueRedis.php index a356e84c65..7dad014e45 100644 --- a/includes/jobqueue/JobQueueRedis.php +++ b/includes/jobqueue/JobQueueRedis.php @@ -18,8 +18,8 @@ * http://www.gnu.org/copyleft/gpl.html * * @file - * @author Aaron Schulz */ +use Psr\Log\LoggerInterface; /** * Class to handle job queues stored in Redis @@ -66,12 +66,16 @@ 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_PUSH_SIZE = 25; // avoid tying up the server + /** * @param array $params Possible keys: * - redisConfig : An array of parameters to RedisConnectionPool::__construct(). @@ -96,6 +100,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() { @@ -208,7 +213,7 @@ class JobQueueRedis extends JobQueue { if ( $flags & self::QOS_ATOMIC ) { $batches = [ $items ]; // all or nothing } else { - $batches = array_chunk( $items, 100 ); // avoid tying up the server + $batches = array_chunk( $items, self::MAX_PUSH_SIZE ); } $failed = 0; $pushed = 0; @@ -250,6 +255,7 @@ class JobQueueRedis extends JobQueue { $args[] = (string)$this->serialize( $item ); } static $script = + /** @lang Lua */ <<getConnection(); try { static $script = + /** @lang Lua */ <<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}." ); @@ -786,9 +794,9 @@ LUA; private function getGlobalKey( $name ) { $parts = [ 'global', 'jobqueue', $name ]; foreach ( $parts as $part ) { - if ( !preg_match( '/[a-zA-Z0-9_-]+/', $part ) ) { - throw new InvalidArgumentException( "Key part characters are out of range." ); - } + if ( !preg_match( '/[a-zA-Z0-9_-]+/', $part ) ) { + throw new InvalidArgumentException( "Key part characters are out of range." ); + } } return implode( ':', $parts );