MediaWiki REL1_30
JobQueueAggregatorRedis.php
Go to the documentation of this file.
1<?php
22use Psr\Log\LoggerInterface;
23
35 protected $redisPool;
37 protected $logger;
39 protected $servers;
40
50 public function __construct( array $params ) {
51 parent::__construct( $params );
52 $this->servers = isset( $params['redisServers'] )
53 ? $params['redisServers']
54 : [ $params['redisServer'] ]; // b/c
55 $params['redisConfig']['serializer'] = 'none';
56 $this->redisPool = RedisConnectionPool::singleton( $params['redisConfig'] );
57 $this->logger = \MediaWiki\Logger\LoggerFactory::getInstance( 'redis' );
58 }
59
60 protected function doNotifyQueueEmpty( $wiki, $type ) {
61 return true; // managed by the service
62 }
63
64 protected function doNotifyQueueNonEmpty( $wiki, $type ) {
65 return true; // managed by the service
66 }
67
68 protected function doGetAllReadyWikiQueues() {
69 $conn = $this->getConnection();
70 if ( !$conn ) {
71 return [];
72 }
73 try {
74 $map = $conn->hGetAll( $this->getReadyQueueKey() );
75
76 if ( is_array( $map ) && isset( $map['_epoch'] ) ) {
77 unset( $map['_epoch'] ); // ignore
78 $pendingDBs = []; // (type => list of wikis)
79 foreach ( $map as $key => $time ) {
80 list( $type, $wiki ) = $this->decodeQueueName( $key );
81 $pendingDBs[$type][] = $wiki;
82 }
83 } else {
84 throw new UnexpectedValueException(
85 "No queue listing found; make sure redisJobChronService is running."
86 );
87 }
88
89 return $pendingDBs;
90 } catch ( RedisException $e ) {
91 $this->redisPool->handleError( $conn, $e );
92
93 return [];
94 }
95 }
96
97 protected function doPurge() {
98 return true; // fully and only refreshed by the service
99 }
100
107 protected function getConnection() {
108 $conn = false;
109 foreach ( $this->servers as $server ) {
110 $conn = $this->redisPool->getConnection( $server, $this->logger );
111 if ( $conn ) {
112 break;
113 }
114 }
115
116 return $conn;
117 }
118
122 private function getReadyQueueKey() {
123 return "jobqueue:aggregator:h-ready-queues:v2"; // global
124 }
125
130 private function decodeQueueName( $name ) {
131 list( $type, $wiki ) = explode( '/', $name, 2 );
132
133 return [ rawurldecode( $type ), rawurldecode( $wiki ) ];
134 }
135}
Class to handle tracking information about all queues using PhpRedis.
array $servers
List of Redis server addresses.
getConnection()
Get a connection to the server that handles all sub-queues for this queue.
Class to handle tracking information about all queues.
Helper class to manage Redis connections.
static singleton(array $options)
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition hooks.txt:1778
returning false will NOT prevent logging $e
Definition hooks.txt:2146
storage can be distributed across multiple servers
Definition memcached.txt:33
$params