* 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 */
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() {
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.
} 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();
}
/* 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 );
}
}