- Removes depreciated variables
- Updates method names
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
namespace MailPoet\Cron;
|
||||
|
||||
use MailPoet\Router\Front as FrontRouter;
|
||||
use MailPoet\Router\Endpoints\Queue as QueueEndpoint;
|
||||
use MailPoet\Models\Setting;
|
||||
use MailPoet\Router\Endpoints\Queue as QueueEndpoint;
|
||||
use MailPoet\Router\Front as FrontRouter;
|
||||
use MailPoet\Util\Security;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
@@ -14,7 +14,7 @@ class CronHelper {
|
||||
const DAEMON_REQUEST_TIMEOUT = 2;
|
||||
const DAEMON_SETTING = 'cron_daemon';
|
||||
|
||||
static function createOrRestartDaemon($token) {
|
||||
static function createDaemon($token) {
|
||||
$daemon = array(
|
||||
'status' => Daemon::STATUS_STARTING,
|
||||
'token' => $token
|
||||
@@ -23,6 +23,10 @@ class CronHelper {
|
||||
return $daemon;
|
||||
}
|
||||
|
||||
static function restartDaemon($token) {
|
||||
return self::createDaemon($token);
|
||||
}
|
||||
|
||||
static function getDaemon() {
|
||||
return Setting::getValue(self::DAEMON_SETTING);
|
||||
}
|
||||
|
@@ -6,21 +6,18 @@ if(!defined('ABSPATH')) exit;
|
||||
class Supervisor {
|
||||
public $daemon;
|
||||
public $token;
|
||||
public $force_run;
|
||||
|
||||
function __construct($force_run = false) {
|
||||
$this->daemon = CronHelper::getDaemon();
|
||||
function __construct() {
|
||||
$this->token = CronHelper::createToken();
|
||||
$this->force_run = $force_run;
|
||||
$this->daemon = $this->getDaemon();
|
||||
}
|
||||
|
||||
function checkDaemon() {
|
||||
$daemon = $this->daemon;
|
||||
$execution_timeout_exceeded = ($daemon) ?
|
||||
(time() - (int)$daemon['updated_at']) > CronHelper::DAEMON_EXECUTION_TIMEOUT :
|
||||
false;
|
||||
if(!$daemon || $execution_timeout_exceeded) {
|
||||
CronHelper::createOrRestartDaemon($this->token);
|
||||
$execution_timeout_exceeded =
|
||||
(time() - (int)$daemon['updated_at']) > CronHelper::DAEMON_EXECUTION_TIMEOUT;
|
||||
if($execution_timeout_exceeded) {
|
||||
CronHelper::restartDaemon($this->token);
|
||||
return $this->runDaemon();
|
||||
}
|
||||
return $daemon;
|
||||
@@ -31,4 +28,13 @@ class Supervisor {
|
||||
$daemon = CronHelper::getDaemon();
|
||||
return $daemon;
|
||||
}
|
||||
|
||||
function getDaemon() {
|
||||
$daemon = CronHelper::getDaemon();
|
||||
if(!$daemon) {
|
||||
CronHelper::createDaemon($this->token);
|
||||
return $this->runDaemon();
|
||||
}
|
||||
return $daemon;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user