Detect not accessible cron daemon [MAILPOET-801]

This adds a function to a CronHelper which detect accessibility problem based on timestamps
which are stored during cron execution. The main idea is that the cron daemon should update run_started_at
within the REQUEST_TIMEOUT after it was accessed (run_accessed_at).
This commit is contained in:
Rostislav Wolny
2018-07-10 18:10:18 +02:00
parent 083372a391
commit 3c7cd193b6
2 changed files with 91 additions and 0 deletions

View File

@@ -84,6 +84,26 @@ class CronHelper {
return WPFunctions::wpRemoteRetrieveBody($result);
}
/**
* @return boolean|null
*/
static function isDaemonAccessible() {
$daemon = self::getDaemon();
if(!$daemon || $daemon['run_accessed_at'] === null) {
return null;
}
if($daemon['run_accessed_at'] <= (int)$daemon['run_started_at']) {
return true;
}
if(
$daemon['run_accessed_at'] + self::DAEMON_REQUEST_TIMEOUT < time() &&
$daemon['run_accessed_at'] > (int)$daemon['run_started_at']
) {
return false;
}
return null;
}
static function queryCronUrl($url) {
$args = WPHooks::applyFilters(
'mailpoet_cron_request_args',