From 58305f675d7dd111243981b2c91462a678feeb53 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 26 Feb 2014 09:07:29 -0500 Subject: [PATCH] Allow configuration of periodic task interval The redis job queue supports delayed jobs but it only checks for them once every 10 pops or once every five minutes. This is fine in production but when running integration tests we want faster turn around time. This allows us to force the periodic task execution to one second in integration tests which speeds them up substantially but leave the standard periodic time calculation in production which is optimized for lower load. Change-Id: I74cf3ca78660bd1ae7c1c88c278a15b4a56f6064 --- includes/job/JobQueueRedis.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/includes/job/JobQueueRedis.php b/includes/job/JobQueueRedis.php index 342266496c..c785cb2130 100644 --- a/includes/job/JobQueueRedis.php +++ b/includes/job/JobQueueRedis.php @@ -71,6 +71,12 @@ class JobQueueRedis extends JobQueue { /** @var string Key to prefix the queue keys with (used for testing) */ protected $key; + /** + * @var null|int maximum seconds between execution of periodic tasks. Used to speed up + * testing but should otherwise be left unset. + */ + protected $maximumPeriodicTaskSeconds; + /** * @params include: * - redisConfig : An array of parameters to RedisConnectionPool::__construct(). @@ -79,6 +85,10 @@ class JobQueueRedis extends JobQueue { * If a hostname is specified but no port, the standard port number * 6379 will be used. Required. * - compression : The type of compression to use; one of (none,gzip). + * - maximumPeriodicTaskSeconds : Maximum seconds between check periodic tasks. Set to + * force faster execution of periodic tasks for inegration tests that + * rely on checkDelay. Without this the integration tests are very very + * slow. This really shouldn't be set in production. * @param array $params */ public function __construct( array $params ) { @@ -87,6 +97,8 @@ class JobQueueRedis extends JobQueue { $this->server = $params['redisServer']; $this->compression = isset( $params['compression'] ) ? $params['compression'] : 'none'; $this->redisPool = RedisConnectionPool::singleton( $params['redisConfig'] ); + $this->maximumPeriodicTaskSeconds = isset( $params['maximumPeriodicTaskSeconds'] ) ? + $params['maximumPeriodicTaskSeconds'] : null; } protected function supportedOrders() { @@ -724,10 +736,16 @@ LUA; if ( $this->checkDelay ) { $periods[] = 300; // 5 minutes } + $period = min( $periods ); + $period = max( $period, 30 ); // sanity + // Support override for faster testing + if ( $this->maximumPeriodicTaskSeconds !== null ) { + $period = min( $period, $this->maximumPeriodicTaskSeconds ); + } return array( 'recyclePruneAndUndelayJobs' => array( 'callback' => array( $this, 'recyclePruneAndUndelayJobs' ), - 'period' => max( min( $periods ), 30 ) // sanity + 'period' => $period, ) ); } -- 2.20.1