Allow passing cron timeouts
[MAILPOET-1114]
This commit is contained in:
committed by
pavel-mailpoet
parent
12225004f4
commit
84dc48daec
@ -48,7 +48,7 @@ class CronHelper {
|
|||||||
return Security::generateRandomString();
|
return Security::generateRandomString();
|
||||||
}
|
}
|
||||||
|
|
||||||
static function pingDaemon($timeout = self::DAEMON_REQUEST_TIMEOUT) {
|
static function pingDaemon($timeout = null) {
|
||||||
$url = self::getCronUrl(
|
$url = self::getCronUrl(
|
||||||
CronDaemonEndpoint::ACTION_PING_RESPONSE
|
CronDaemonEndpoint::ACTION_PING_RESPONSE
|
||||||
);
|
);
|
||||||
@ -58,7 +58,7 @@ class CronHelper {
|
|||||||
wp_remote_retrieve_body($result);
|
wp_remote_retrieve_body($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function accessDaemon($token, $timeout = self::DAEMON_REQUEST_TIMEOUT) {
|
static function accessDaemon($token, $timeout = null) {
|
||||||
$data = array('token' => $token);
|
$data = array('token' => $token);
|
||||||
$url = self::getCronUrl(
|
$url = self::getCronUrl(
|
||||||
CronDaemonEndpoint::ACTION_RUN,
|
CronDaemonEndpoint::ACTION_RUN,
|
||||||
@ -78,6 +78,13 @@ class CronHelper {
|
|||||||
return wp_remote_get($url, $args);
|
return wp_remote_get($url, $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function getCronTimeout($timeout = null) {
|
||||||
|
if($timeout) return $timeout;
|
||||||
|
$custom_timeout = WPHooks::applyFilters('mailpoet_cron_request_timeout', $timeout);
|
||||||
|
if(!$custom_timeout) return self::DAEMON_REQUEST_TIMEOUT;
|
||||||
|
return $custom_timeout;
|
||||||
|
}
|
||||||
|
|
||||||
static function getCronUrl($action, $data = false) {
|
static function getCronUrl($action, $data = false) {
|
||||||
$url = Router::buildRequest(
|
$url = Router::buildRequest(
|
||||||
CronDaemonEndpoint::ENDPOINT,
|
CronDaemonEndpoint::ENDPOINT,
|
||||||
|
@ -128,6 +128,23 @@ class CronHelperTest extends \MailPoetTest {
|
|||||||
remove_filter('mailpoet_cron_request_url', $filter);
|
remove_filter('mailpoet_cron_request_url', $filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testItAllowsSettingCustomCronTimeout() {
|
||||||
|
$filterFunction = function() {
|
||||||
|
return 5;
|
||||||
|
};
|
||||||
|
add_filter('mailpoet_cron_request_timeout', $filterFunction);
|
||||||
|
expect(CronHelper::getCronTimeout())->equals(5);
|
||||||
|
remove_filter('mailpoet_cron_request_timeout', $filterFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItWorksWithDefaultCronTimeout() {
|
||||||
|
expect(CronHelper::getCronTimeout())->equals(CronHelper::DAEMON_REQUEST_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItWorksWithCustomCronTimeout() {
|
||||||
|
expect(CronHelper::getCronTimeout(12))->equals(12);
|
||||||
|
}
|
||||||
|
|
||||||
function testItReturnsErrorMessageAsPingResposneWhenCronUrlCannotBeAccessed() {
|
function testItReturnsErrorMessageAsPingResposneWhenCronUrlCannotBeAccessed() {
|
||||||
Mock::double('MailPoet\Cron\CronHelper', [
|
Mock::double('MailPoet\Cron\CronHelper', [
|
||||||
'getSiteUrl' => false
|
'getSiteUrl' => false
|
||||||
|
Reference in New Issue
Block a user