Allow modifing cron limits

[MAILPOET-2367]
This commit is contained in:
Pavel Dohnal
2019-09-23 14:29:51 +02:00
committed by Jack Kitterhing
parent 4d3a005b20
commit 1bedf1fd1a
5 changed files with 19 additions and 7 deletions

View File

@@ -6,16 +6,29 @@ use MailPoet\Router\Endpoints\CronDaemon as CronDaemonEndpoint;
use MailPoet\Router\Router;
use MailPoet\Settings\SettingsController;
use MailPoet\Util\Security;
use MailPoet\WP\Functions;
use MailPoet\WP\Functions as WPFunctions;
class CronHelper {
const DAEMON_EXECUTION_LIMIT = 20; // seconds
const DAEMON_EXECUTION_TIMEOUT = 35; // seconds
const DAEMON_REQUEST_TIMEOUT = 5; // seconds
const DAEMON_SETTING = 'cron_daemon';
const DAEMON_STATUS_ACTIVE = 'active';
const DAEMON_STATUS_INACTIVE = 'inactive';
static function getDaemonExecutionLimit() {
$wp = Functions::get();
$limit = $wp->applyFilters('mailpoet_cron_get_execution_limit', self::DAEMON_EXECUTION_LIMIT);
return $limit;
}
static function getDaemonExecutionTimeout() {
$limit = self::getDaemonExecutionLimit();
$timeout = $limit * 1.75;
$wp = Functions::get();
return $wp->applyFilters('mailpoet_cron_get_execution_timeout', $timeout);
}
static function createDaemon($token) {
$daemon = [
'token' => $token,
@@ -189,7 +202,7 @@ class CronHelper {
static function enforceExecutionLimit($timer) {
$elapsed_time = microtime(true) - $timer;
if ($elapsed_time >= self::DAEMON_EXECUTION_LIMIT) {
if ($elapsed_time >= self::getDaemonExecutionLimit()) {
throw new \Exception(__('Maximum execution time has been reached.', 'mailpoet'));
}
}