- Adds new "ping" cron daemon router endpoint

- Removes the requirement to have data payload for router requests
This commit is contained in:
Vlad
2017-01-08 20:46:24 -05:00
parent aa0078e5e4
commit a6b00e1ba7
7 changed files with 88 additions and 37 deletions

View File

@@ -2,7 +2,7 @@
namespace MailPoet\Cron;
use MailPoet\Models\Setting;
use MailPoet\Router\Endpoints\Queue as QueueEndpoint;
use MailPoet\Router\Endpoints\CronDaemon as CronDaemonEndpoint;
use MailPoet\Router\Router;
use MailPoet\Util\Security;
@@ -46,11 +46,27 @@ class CronHelper {
return Security::generateRandomString();
}
static function pingDaemon() {
$url = Router::buildRequest(
CronDaemonEndpoint::ENDPOINT,
CronDaemonEndpoint::ACTION_PING_RESPONSE
);
$url = str_replace(home_url(), self::getSiteUrl(), $url);
$args = array(
'blocking' => true,
'sslverify' => false,
'timeout' => self::DAEMON_REQUEST_TIMEOUT,
'user-agent' => 'MailPoet (www.mailpoet.com) Cron'
);
$result = wp_remote_get($url, $args);
return wp_remote_retrieve_body($result) === 'pong';
}
static function accessDaemon($token, $timeout = self::DAEMON_REQUEST_TIMEOUT) {
$data = array('token' => $token);
$url = Router::buildRequest(
QueueEndpoint::ENDPOINT,
QueueEndpoint::ACTION_RUN,
CronDaemonEndpoint::ENDPOINT,
CronDaemonEndpoint::ACTION_RUN,
$data
);
$url = str_replace(home_url(), self::getSiteUrl(), $url);