MediaWiki master
MediaWiki\PoolCounter\PoolCounterWork Class Reference

Class for dealing with PoolCounters using class members. More...

Inherited by MediaWiki\PoolCounter\PoolCounterWorkViaCallback, and MediaWiki\PoolCounter\PoolWorkArticleView.

Public Member Functions

 __construct (string $type, string $key, PoolCounter $poolCounter=null)
 
 doWork ()
 Actually perform the work, caching it if needed.
 
 error ( $status)
 Do something with the error, like showing it to the user.
 
 execute ( $skipcache=false)
 Get the result of the work (whatever it is), or the result of the error() function.
 
 fallback ( $fast)
 A work not so good (eg.
 
 getCachedWork ()
 Retrieve the work from cache.
 
 logError ( $status)
 Log an error.
 

Protected Member Functions

 isFastStaleEnabled ()
 Should fast stale mode be used?
 

Protected Attributes

bool $cacheable = false
 
string $type = 'generic'
 

Detailed Description

Class for dealing with PoolCounters using class members.

Definition at line 29 of file PoolCounterWork.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\PoolCounter\PoolCounterWork::__construct ( string $type,
string $key,
PoolCounter $poolCounter = null )
Parameters
string$typeThe class of actions to limit concurrency for (task type)
string$keyKey that identifies the queue this work is placed on
PoolCounter | null$poolCounter

Definition at line 42 of file PoolCounterWork.php.

References MediaWiki\PoolCounter\PoolCounterWork\$type, and MediaWiki\MediaWikiServices\getInstance().

Member Function Documentation

◆ doWork()

MediaWiki\PoolCounter\PoolCounterWork::doWork ( )
abstract

◆ error()

MediaWiki\PoolCounter\PoolCounterWork::error ( $status)

Do something with the error, like showing it to the user.

Parameters
Status$status
Returns
mixed|false

Reimplemented in MediaWiki\PoolCounter\PoolCounterWorkViaCallback, and MediaWiki\PoolCounter\PoolWorkArticleView.

Definition at line 82 of file PoolCounterWork.php.

Referenced by MediaWiki\PoolCounter\PoolCounterWork\execute().

◆ execute()

MediaWiki\PoolCounter\PoolCounterWork::execute ( $skipcache = false)

Get the result of the work (whatever it is), or the result of the error() function.

This returns the result of the one of the following methods:

  • doWork(): Applies if the work is exclusive or no other process is doing it, and on the condition that either this process successfully entered the pool or the pool counter is down.
  • doCachedWork(): Applies if the work is cacheable and this blocked on another process which finished the work.
  • fallback(): Applies for all remaining cases.

If these all return false, then the result of error() is returned.

In slow-stale mode, these three methods are called in the sequence given above, and the first non-false response is used. This means in case of concurrent cache-miss requests for the same revision, later ones will load on DBs and other backend services, and wait for earlier requests to succeed and then read out their saved result.

In fast-stale mode, if other requests hold doWork lock already, we call fallback() first to let it try to find an acceptable return value. If fallback() returns false, then we will wait for the doWork lock, as for slow stale mode, including potentially calling fallback() a second time.

Parameters
bool$skipcache
Returns
mixed

Definition at line 137 of file PoolCounterWork.php.

References MediaWiki\PoolCounter\PoolCounter\DONE, MediaWiki\PoolCounter\PoolCounterWork\doWork(), MediaWiki\PoolCounter\PoolCounter\ERROR, MediaWiki\PoolCounter\PoolCounterWork\error(), MediaWiki\PoolCounter\PoolCounterWork\execute(), MediaWiki\PoolCounter\PoolCounterWork\fallback(), MediaWiki\PoolCounter\PoolCounterWork\getCachedWork(), MediaWiki\PoolCounter\PoolCounterWork\isFastStaleEnabled(), MediaWiki\PoolCounter\PoolCounter\LOCK_HELD, MediaWiki\PoolCounter\PoolCounter\LOCKED, MediaWiki\PoolCounter\PoolCounterWork\logError(), MediaWiki\PoolCounter\PoolCounter\QUEUE_FULL, and MediaWiki\PoolCounter\PoolCounter\TIMEOUT.

Referenced by DjVuHandler\doTransform(), MediaWiki\Specials\SpecialContributions\execute(), MediaWiki\PoolCounter\PoolCounterWork\execute(), MediaWiki\FileRepo\ThumbnailEntryPoint\generateThumbnail(), and File\getThumbnailSource().

◆ fallback()

MediaWiki\PoolCounter\PoolCounterWork::fallback ( $fast)

A work not so good (eg.

expired one) but better than an error message.

Parameters
bool$fastTrue if PoolCounter is requesting a fast stale response (pre-wait)
Returns
mixed|false Work result or false

Reimplemented in MediaWiki\PoolCounter\PoolCounterWorkViaCallback, and MediaWiki\PoolCounter\PoolWorkArticleViewCurrent.

Definition at line 72 of file PoolCounterWork.php.

Referenced by MediaWiki\PoolCounter\PoolCounterWork\execute().

◆ getCachedWork()

MediaWiki\PoolCounter\PoolCounterWork::getCachedWork ( )

Retrieve the work from cache.

Returns
mixed|false Work result or false

Reimplemented in MediaWiki\PoolCounter\PoolCounterWorkViaCallback, MediaWiki\PoolCounter\PoolWorkArticleViewCurrent, and MediaWiki\PoolCounter\PoolWorkArticleViewOld.

Definition at line 61 of file PoolCounterWork.php.

Referenced by MediaWiki\PoolCounter\PoolCounterWork\execute().

◆ isFastStaleEnabled()

MediaWiki\PoolCounter\PoolCounterWork::isFastStaleEnabled ( )
protected

Should fast stale mode be used?

Returns
bool

Definition at line 91 of file PoolCounterWork.php.

Referenced by MediaWiki\PoolCounter\PoolCounterWork\execute().

◆ logError()

MediaWiki\PoolCounter\PoolCounterWork::logError ( $status)

Log an error.

Parameters
Status$status
Returns
void

Definition at line 101 of file PoolCounterWork.php.

Referenced by MediaWiki\PoolCounter\PoolCounterWork\execute().

Member Data Documentation

◆ $cacheable

bool MediaWiki\PoolCounter\PoolCounterWork::$cacheable = false
protected

◆ $type

string MediaWiki\PoolCounter\PoolCounterWork::$type = 'generic'
protected

The documentation for this class was generated from the following file: