<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing namespace MailPoet\Cron; if (!defined('ABSPATH')) exit; class Supervisor { public $daemon; public $token; /** @var CronHelper */ private $cronHelper; public function __construct( CronHelper $cronHelper ) { $this->cronHelper = $cronHelper; } public function init() { $this->token = $this->cronHelper->createToken(); $this->daemon = $this->getDaemon(); } public function checkDaemon() { $daemon = $this->daemon; $updatedAt = $daemon ? (int)$daemon['updated_at'] : 0; $executionTimeoutExceeded = (time() - $updatedAt) >= $this->cronHelper->getDaemonExecutionTimeout(); $daemonIsInactive = isset($daemon['status']) && $daemon['status'] === CronHelper::DAEMON_STATUS_INACTIVE; if ($executionTimeoutExceeded || $daemonIsInactive) { $this->cronHelper->restartDaemon($this->token); return $this->runDaemon(); } return $daemon; } public function runDaemon() { $this->cronHelper->accessDaemon($this->token); $daemon = $this->cronHelper->getDaemon(); return $daemon; } public function getDaemon() { $daemon = $this->cronHelper->getDaemon(); if (!$daemon) { $this->cronHelper->createDaemon($this->token); return $this->runDaemon(); } return $daemon; } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
ActionScheduler | Folder | 0755 |
|
|
Triggers | Folder | 0755 |
|
|
Workers | Folder | 0755 |
|
|
CronHelper.php | File | 7.13 KB | 0644 |
|
CronTrigger.php | File | 2.39 KB | 0644 |
|
CronWorkerInterface.php | File | 939 B | 0644 |
|
CronWorkerRunner.php | File | 5.81 KB | 0644 |
|
CronWorkerScheduler.php | File | 2.77 KB | 0644 |
|
Daemon.php | File | 4.33 KB | 0644 |
|
DaemonActionSchedulerRunner.php | File | 2.04 KB | 0644 |
|
DaemonHttpRunner.php | File | 4.67 KB | 0644 |
|
Supervisor.php | File | 1.36 KB | 0644 |
|
index.php | File | 6 B | 0644 |
|