diff --git a/lib/Cron/CronHelper.php b/lib/Cron/CronHelper.php index 9794b14f4e..bc073a6d85 100644 --- a/lib/Cron/CronHelper.php +++ b/lib/Cron/CronHelper.php @@ -7,6 +7,9 @@ use MailPoet\Util\Security; if(!defined('ABSPATH')) exit; class CronHelper { + static $daemon_execution_limit = 30; + static $daemon_timeout_limit = 30; + static function createDaemon($token) { $daemon = array( 'status' => 'starting', diff --git a/lib/Cron/Daemon.php b/lib/Cron/Daemon.php index 2b83b96405..9bd9a8949d 100644 --- a/lib/Cron/Daemon.php +++ b/lib/Cron/Daemon.php @@ -11,7 +11,6 @@ class Daemon { public $daemon; public $request_payload; public $refreshed_token; - private $execution_time_limit = 30; private $timer; function __construct($request_payload = array()) { @@ -40,12 +39,12 @@ class Daemon { } catch(Exception $e) { } $elapsed_time = microtime(true) - $this->timer; - if($elapsed_time < $this->execution_time_limit) { - sleep($this->execution_time_limit - $elapsed_time); + if($elapsed_time < CronHelper::$daemon_execution_limit) { + sleep(CronHelper::$daemon_execution_limit - $elapsed_time); } - // after each execution, re-read daemon data in case its status has changed + // after each execution, re-read daemon data in case it was deleted or + // its status has changed $daemon = CronHelper::getDaemon(); - // if the token has changed, abort further processing if(!$daemon || $daemon['token'] !== $this->request_payload['token']) { exit; } diff --git a/lib/Cron/Supervisor.php b/lib/Cron/Supervisor.php index 9bda7ac52e..3e9bd9371b 100644 --- a/lib/Cron/Supervisor.php +++ b/lib/Cron/Supervisor.php @@ -7,7 +7,6 @@ class Supervisor { public $daemon; public $token; public $force_run; - private $timeout_limit = 40; function __construct($force_run = false) { $this->daemon = CronHelper::getDaemon(); @@ -32,13 +31,13 @@ class Supervisor { $elapsed_time = time() - (int) $daemon['updated_at']; // if it's been less than 40 seconds since last execution and we're not // force-running the daemon, return its status and do nothing - if($elapsed_time < $this->timeout_limit && !$this->force_run) { + if($elapsed_time < CronHelper::$daemon_timeout_limit && !$this->force_run) { return $this->formatDaemonStatusMessage($daemon['status']); } // if it's been less than 40 seconds since last execution, we are // force-running the daemon and it's either being started or stopped, // return its status and do nothing - elseif($elapsed_time < $this->timeout_limit && + elseif($elapsed_time < CronHelper::$daemon_timeout_limit && $this->force_run && in_array($daemon['status'], array( 'stopping', diff --git a/lib/Cron/Workers/SendingQueue.php b/lib/Cron/Workers/SendingQueue.php index 1424c71b13..9d13b5c753 100644 --- a/lib/Cron/Workers/SendingQueue.php +++ b/lib/Cron/Workers/SendingQueue.php @@ -1,6 +1,7 @@ timer = ($timer) ? $timer : microtime(true); @@ -120,7 +121,7 @@ class SendingQueue { function checkExecutionTimer() { $elapsed_time = microtime(true) - $this->timer; - if($elapsed_time >= 30) throw new \Exception('Maximum execution time reached.'); + if($elapsed_time >= CronHelper::$daemon_execution_limit) throw new \Exception(__('Maximum execution time reached.')); } function getQueues() {