wp = $wp; $this->wordpressTrigger = $wordpressTrigger; $this->remoteExecutorHandler = $remoteExecutorHandler; $this->actionScheduler = $actionScheduler; } public function init() { $this->wp->addAction(self::NAME, [$this, 'process']); if (!$this->actionScheduler->hasScheduledAction(self::NAME)) { $this->actionScheduler->scheduleRecurringAction($this->wp->currentTime('timestamp', true), self::TRIGGER_RUN_INTERVAL, self::NAME); } } /** * It checks if there are scheduled tasks to execute. * In case there are tasks to do, it schedules a daemon-run action. */ public function process(): void { $hasJobsToDo = $this->wordpressTrigger->checkExecutionRequirements(); if (!$hasJobsToDo) { $this->actionScheduler->unscheduleAction(DaemonRun::NAME); return; } if ($this->actionScheduler->hasScheduledAction(DaemonRun::NAME)) { return; } // Schedule immediate action for execution of the daemon $this->actionScheduler->scheduleImmediateSingleAction(DaemonRun::NAME); $this->remoteExecutorHandler->triggerExecutor(); } }