MediaWiki  1.30.2
JobQueueAggregatorRedis.php
Go to the documentation of this file.
1 <?php
22 use 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 }
RedisConnectionPool\singleton
static singleton(array $options)
Definition: RedisConnectionPool.php:147
JobQueueAggregatorRedis\doNotifyQueueEmpty
doNotifyQueueEmpty( $wiki, $type)
Definition: JobQueueAggregatorRedis.php:60
JobQueueAggregatorRedis\doGetAllReadyWikiQueues
doGetAllReadyWikiQueues()
Definition: JobQueueAggregatorRedis.php:68
servers
storage can be distributed across multiple servers
Definition: memcached.txt:33
MediaWiki\Logger\LoggerFactory\getInstance
static getInstance( $channel)
Get a named logger instance from the currently configured logger factory.
Definition: LoggerFactory.php:92
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
$params
$params
Definition: styleTest.css.php:40
JobQueueAggregatorRedis\doPurge
doPurge()
Definition: JobQueueAggregatorRedis.php:97
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
JobQueueAggregator
Class to handle tracking information about all queues.
Definition: JobQueueAggregator.php:29
JobQueueAggregatorRedis\$servers
array $servers
List of Redis server addresses.
Definition: JobQueueAggregatorRedis.php:39
JobQueueAggregatorRedis\decodeQueueName
decodeQueueName( $name)
Definition: JobQueueAggregatorRedis.php:130
$time
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1778
list
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
JobQueueAggregatorRedis\$logger
LoggerInterface $logger
Definition: JobQueueAggregatorRedis.php:37
JobQueueAggregatorRedis
Class to handle tracking information about all queues using PhpRedis.
Definition: JobQueueAggregatorRedis.php:33
RedisConnectionPool
Helper class to manage Redis connections.
Definition: RedisConnectionPool.php:40
JobQueueAggregatorRedis\$redisPool
RedisConnectionPool $redisPool
Definition: JobQueueAggregatorRedis.php:35
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2141
JobQueueAggregatorRedis\__construct
__construct(array $params)
Definition: JobQueueAggregatorRedis.php:50
JobQueueAggregatorRedis\getConnection
getConnection()
Get a connection to the server that handles all sub-queues for this queue.
Definition: JobQueueAggregatorRedis.php:107
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
JobQueueAggregatorRedis\doNotifyQueueNonEmpty
doNotifyQueueNonEmpty( $wiki, $type)
Definition: JobQueueAggregatorRedis.php:64
array
the array() calling protocol came about after MediaWiki 1.4rc1.
JobQueueAggregatorRedis\getReadyQueueKey
getReadyQueueKey()
Definition: JobQueueAggregatorRedis.php:122
$type
$type
Definition: testCompression.php:48