X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FPoolCounter.php;h=25bdd2d52a7d4c0da18f16946f7a351a7b1bd201;hb=b066397f10008e30242afa3eeb0af692502e419e;hp=825ae34ca15409318bf86d9ce559642476e3d2aa;hpb=5a244555e3c545c7d0b53d08286dd1fee16092a5;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/PoolCounter.php b/includes/PoolCounter.php index 825ae34ca1..25bdd2d52a 100644 --- a/includes/PoolCounter.php +++ b/includes/PoolCounter.php @@ -9,8 +9,10 @@ * of the cpu of the pool. This is also known as 'Michael Jackson effect'. * The PoolCounter provides semaphore semantics for restricting the number * of workers that may be concurrently performing such single task. + * + * By default PoolCounter_Stub is used, which provides no locking. You + * can get a useful one in the PoolCounter extension. */ - abstract class PoolCounter { /* Return codes */ @@ -82,15 +84,15 @@ abstract class PoolCounter { class PoolCounter_Stub extends PoolCounter { function acquireForMe() { - return PoolCounter::LOCKED; + return Status::newGood( PoolCounter::LOCKED ); } function acquireForAnyone() { - return PoolCounter::LOCKED; + return Status::newGood( PoolCounter::LOCKED ); } function release() { - return PoolCounter::RELEASED; + return Status::newGood( PoolCounter::RELEASED ); } public function __construct() { @@ -132,6 +134,13 @@ abstract class PoolCounterWork { function error( $status ) { return false; } + + /** + * Log an error + */ + function logError( $status ) { + wfDebugLog( 'poolcounter', $status->getWikiText() ); + } /** * Get the result of the work (whatever it is), or false. @@ -142,9 +151,14 @@ abstract class PoolCounterWork { } else { $status = $this->poolCounter->acquireForMe(); } - - $result = false; - switch ( is_int( $status ) ? $status : PoolCounter::ERROR ) { + + if ( !$status->isOK() ) { + // Respond gracefully to complete server breakage: just log it and do the work + $this->logError( $status ); + return $this->doWork(); + } + + switch ( $status->value ) { case PoolCounter::LOCKED: $result = $this->doWork(); $this->poolCounter->release(); @@ -169,8 +183,13 @@ abstract class PoolCounterWork { } /* no break */ + /* These two cases should never be hit... */ case PoolCounter::ERROR: default: + $errors = array( PoolCounter::QUEUE_FULL => 'pool-queuefull', PoolCounter::TIMEOUT => 'pool-timeout' ); + + $status = Status::newFatal( isset($errors[$status->value]) ? $errors[$status->value] : 'pool-errorunknown' ); + $this->logError( $status ); return $this->error( $status ); } }