MediaWiki  1.23.2
JobQueueAggregatorMemc.php
Go to the documentation of this file.
1 <?php
32  protected $cache;
33 
34  protected $cacheTTL; // integer; seconds
35 
43  protected function __construct( array $params ) {
44  parent::__construct( $params );
45  $this->cache = isset( $params['objectCache'] )
46  ? wfGetCache( $params['objectCache'] )
47  : wfGetMainCache();
48  $this->cacheTTL = isset( $params['cacheTTL'] ) ? $params['cacheTTL'] : 180; // 3 min
49  }
50 
54  protected function doNotifyQueueEmpty( $wiki, $type ) {
55  $key = $this->getReadyQueueCacheKey();
56  // Delist the queue from the "ready queue" list
57  if ( $this->cache->add( "$key:lock", 1, 60 ) ) { // lock
58  $curInfo = $this->cache->get( $key );
59  if ( is_array( $curInfo ) && isset( $curInfo['pendingDBs'][$type] ) ) {
60  if ( in_array( $wiki, $curInfo['pendingDBs'][$type] ) ) {
61  $curInfo['pendingDBs'][$type] = array_diff(
62  $curInfo['pendingDBs'][$type], array( $wiki ) );
63  $this->cache->set( $key, $curInfo );
64  }
65  }
66  $this->cache->delete( "$key:lock" ); // unlock
67  }
68 
69  return true;
70  }
71 
75  protected function doNotifyQueueNonEmpty( $wiki, $type ) {
76  return true; // updated periodically
77  }
78 
82  protected function doGetAllReadyWikiQueues() {
83  $key = $this->getReadyQueueCacheKey();
84  // If the cache entry wasn't present, is stale, or in .1% of cases otherwise,
85  // regenerate the cache. Use any available stale cache if another process is
86  // currently regenerating the pending DB information.
87  $pendingDbInfo = $this->cache->get( $key );
88  if ( !is_array( $pendingDbInfo )
89  || ( time() - $pendingDbInfo['timestamp'] ) > $this->cacheTTL
90  || mt_rand( 0, 999 ) == 0
91  ) {
92  if ( $this->cache->add( "$key:rebuild", 1, 1800 ) ) { // lock
93  $pendingDbInfo = array(
94  'pendingDBs' => $this->findPendingWikiQueues(),
95  'timestamp' => time()
96  );
97  for ( $attempts = 1; $attempts <= 25; ++$attempts ) {
98  if ( $this->cache->add( "$key:lock", 1, 60 ) ) { // lock
99  $this->cache->set( $key, $pendingDbInfo );
100  $this->cache->delete( "$key:lock" ); // unlock
101  break;
102  }
103  }
104  $this->cache->delete( "$key:rebuild" ); // unlock
105  }
106  }
107 
108  return is_array( $pendingDbInfo )
109  ? $pendingDbInfo['pendingDBs']
110  : array(); // cache is both empty and locked
111  }
112 
116  protected function doPurge() {
117  return $this->cache->delete( $this->getReadyQueueCacheKey() );
118  }
119 
123  private function getReadyQueueCacheKey() {
124  return "jobqueue:aggregator:ready-queues:v1"; // global
125  }
126 }
JobQueueAggregatorMemc\__construct
__construct(array $params)
@params include:
Definition: JobQueueAggregatorMemc.php:42
JobQueueAggregatorMemc\getReadyQueueCacheKey
getReadyQueueCacheKey()
Definition: JobQueueAggregatorMemc.php:122
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
JobQueueAggregatorMemc\doGetAllReadyWikiQueues
doGetAllReadyWikiQueues()
Definition: JobQueueAggregatorMemc.php:81
JobQueueAggregatorMemc
Class to handle tracking information about all queues using BagOStuff.
Definition: JobQueueAggregatorMemc.php:30
JobQueueAggregatorMemc\$cacheTTL
$cacheTTL
Definition: JobQueueAggregatorMemc.php:33
$params
$params
Definition: styleTest.css.php:40
JobQueueAggregatorMemc\$cache
BagOStuff $cache
Definition: JobQueueAggregatorMemc.php:31
wfGetCache
wfGetCache( $inputType)
Get a cache object.
Definition: GlobalFunctions.php:3948
BagOStuff
interface is intended to be more or less compatible with the PHP memcached client.
Definition: BagOStuff.php:43
cache
you have access to all of the normal MediaWiki so you can get a DB use the cache
Definition: maintenance.txt:52
JobQueueAggregator
Class to handle tracking information about all queues.
Definition: JobQueueAggregator.php:30
wfGetMainCache
wfGetMainCache()
Get the main cache object.
Definition: GlobalFunctions.php:3957
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
JobQueueAggregatorMemc\doNotifyQueueEmpty
doNotifyQueueEmpty( $wiki, $type)
Definition: JobQueueAggregatorMemc.php:53
JobQueueAggregatorMemc\doPurge
doPurge()
Definition: JobQueueAggregatorMemc.php:115
JobQueueAggregatorMemc\doNotifyQueueNonEmpty
doNotifyQueueNonEmpty( $wiki, $type)
Definition: JobQueueAggregatorMemc.php:74
JobQueueAggregator\findPendingWikiQueues
findPendingWikiQueues()
Get all databases that have a pending job.
Definition: JobQueueAggregator.php:150
$type
$type
Definition: testCompression.php:46