Use CronHelper service in cron core classes [MAILPOET-2459]

This commit is contained in:
wxa
2019-10-30 16:23:22 +03:00
committed by Jack Kitterhing
parent ed7784d945
commit 3436fed6e7
11 changed files with 90 additions and 59 deletions

View File

@@ -15,14 +15,18 @@ class DaemonHttpRunner {
/** @var Daemon */
private $daemon;
/** @var CronHelper */
private $cron_helper;
/** @var SettingsController */
private $settings;
const PING_SUCCESS_RESPONSE = 'pong';
function __construct(Daemon $daemon = null, SettingsController $settings) {
$this->settings_daemon_data = CronHelper::getDaemon();
$this->token = CronHelper::createToken();
function __construct(Daemon $daemon = null, CronHelper $cron_helper, SettingsController $settings) {
$this->cron_helper = $cron_helper;
$this->settings_daemon_data = $this->cron_helper->getDaemon();
$this->token = $this->cron_helper->createToken();
$this->timer = microtime(true);
$this->daemon = $daemon;
$this->settings = $settings;
@@ -74,12 +78,12 @@ class DaemonHttpRunner {
// if workers took less time to execute than the daemon execution limit,
// pause daemon execution to ensure that daemon runs only once every X seconds
$elapsed_time = microtime(true) - $this->timer;
if ($elapsed_time < CronHelper::getDaemonExecutionLimit()) {
$this->pauseExecution(CronHelper::getDaemonExecutionLimit() - $elapsed_time);
if ($elapsed_time < $this->cron_helper->getDaemonExecutionLimit()) {
$this->pauseExecution($this->cron_helper->getDaemonExecutionLimit() - $elapsed_time);
}
}
// after each execution, re-read daemon data in case it changed
$settings_daemon_data = CronHelper::getDaemon();
$settings_daemon_data = $this->cron_helper->getDaemon();
if ($this->shouldTerminateExecution($settings_daemon_data)) {
return $this->terminateRequest();
}
@@ -91,7 +95,7 @@ class DaemonHttpRunner {
}
function callSelf() {
CronHelper::accessDaemon($this->token);
$this->cron_helper->accessDaemon($this->token);
$this->terminateRequest();
}