* Use ApiBase::dieDebug() to render maxlag error properly
* Allow modules to ignore maxlag attribute
This commit is contained in:
parent
d795622bfb
commit
d7908b82e0
4 changed files with 32 additions and 11 deletions
|
|
@ -532,6 +532,14 @@ abstract class ApiBase {
|
|||
return $this->mRawFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if API needs to check maxlag
|
||||
*/
|
||||
public function shouldCheckMaxlag() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Profiling: total module execution time
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -46,6 +46,10 @@ class ApiHelp extends ApiBase {
|
|||
$this->dieUsage('', 'help');
|
||||
}
|
||||
|
||||
public function shouldCheckMaxlag() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function getDescription() {
|
||||
return array (
|
||||
'Display this help screen.'
|
||||
|
|
|
|||
|
|
@ -186,17 +186,6 @@ class ApiMain extends ApiBase {
|
|||
* have been accumulated, and replace it with an error message and a help screen.
|
||||
*/
|
||||
protected function executeActionWithErrorHandling() {
|
||||
$params = $this->extractRequestParams();
|
||||
if( isset( $params['maxlag'] ) ) {
|
||||
// Check for maxlag
|
||||
global $wgLoadBalancer;
|
||||
$maxLag = $params['maxlag'];
|
||||
list( $host, $lag ) = $wgLoadBalancer->getMaxLag();
|
||||
if ( $lag > $maxLag ) {
|
||||
wfMaxlagError( $host, $lag, $maxLag );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// In case an error occurs during data output,
|
||||
// clear the output buffer and print just the error information
|
||||
|
|
@ -301,6 +290,21 @@ class ApiMain extends ApiBase {
|
|||
|
||||
// Instantiate the module requested by the user
|
||||
$module = new $this->mModules[$this->mAction] ($this, $this->mAction);
|
||||
|
||||
if( $module->shouldCheckMaxlag() && isset( $params['maxlag'] ) ) {
|
||||
// Check for maxlag
|
||||
global $wgLoadBalancer, $wgShowHostnames;
|
||||
$maxLag = $params['maxlag'];
|
||||
list( $host, $lag ) = $wgLoadBalancer->getMaxLag();
|
||||
if ( $lag > $maxLag ) {
|
||||
if( $wgShowHostnames ) {
|
||||
ApiBase :: dieUsage( "Waiting for $host: $lag seconds lagged", 'maxlag' );
|
||||
} else {
|
||||
ApiBase :: dieUsage( "Waiting for a database server: $lag seconds lagged", 'maxlag' );
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->mInternalMode) {
|
||||
|
||||
|
|
|
|||
|
|
@ -456,6 +456,11 @@ class ApiQuery extends ApiBase {
|
|||
$psModule = new ApiPageSet($this);
|
||||
return $psModule->makeHelpMsgParameters() . parent :: makeHelpMsgParameters();
|
||||
}
|
||||
|
||||
// @todo should work correctly
|
||||
public function shouldCheckMaxlag() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function getParamDescription() {
|
||||
return array (
|
||||
|
|
|
|||
Loading…
Reference in a new issue