ActionScheduler
2 months ago
CliCommands
1 month ago
Triggers
2 months ago
Workers
2 days ago
CronHelper.php
2 months ago
CronTrigger.php
2 years ago
CronWorkerInterface.php
3 years ago
CronWorkerRunner.php
2 months ago
CronWorkerScheduler.php
10 months ago
Daemon.php
2 days ago
DaemonActionSchedulerRunner.php
6 months ago
DaemonHttpRunner.php
2 months ago
Supervisor.php
3 years ago
index.php
3 years ago
Supervisor.php
55 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Cron; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | class Supervisor { |
| 9 | public $daemon; |
| 10 | public $token; |
| 11 | |
| 12 | /** @var CronHelper */ |
| 13 | private $cronHelper; |
| 14 | |
| 15 | public function __construct( |
| 16 | CronHelper $cronHelper |
| 17 | ) { |
| 18 | $this->cronHelper = $cronHelper; |
| 19 | } |
| 20 | |
| 21 | public function init() { |
| 22 | $this->token = $this->cronHelper->createToken(); |
| 23 | $this->daemon = $this->getDaemon(); |
| 24 | } |
| 25 | |
| 26 | public function checkDaemon() { |
| 27 | $daemon = $this->daemon; |
| 28 | $updatedAt = $daemon ? (int)$daemon['updated_at'] : 0; |
| 29 | $executionTimeoutExceeded = |
| 30 | (time() - $updatedAt) >= $this->cronHelper->getDaemonExecutionTimeout(); |
| 31 | $daemonIsInactive = |
| 32 | isset($daemon['status']) && $daemon['status'] === CronHelper::DAEMON_STATUS_INACTIVE; |
| 33 | if ($executionTimeoutExceeded || $daemonIsInactive) { |
| 34 | $this->cronHelper->restartDaemon($this->token); |
| 35 | return $this->runDaemon(); |
| 36 | } |
| 37 | return $daemon; |
| 38 | } |
| 39 | |
| 40 | public function runDaemon() { |
| 41 | $this->cronHelper->accessDaemon($this->token); |
| 42 | $daemon = $this->cronHelper->getDaemon(); |
| 43 | return $daemon; |
| 44 | } |
| 45 | |
| 46 | public function getDaemon() { |
| 47 | $daemon = $this->cronHelper->getDaemon(); |
| 48 | if (!$daemon) { |
| 49 | $this->cronHelper->createDaemon($this->token); |
| 50 | return $this->runDaemon(); |
| 51 | } |
| 52 | return $daemon; |
| 53 | } |
| 54 | } |
| 55 |