Skip to content

Commit

Permalink
Replace status closure in Scheduler to reference link
Browse files Browse the repository at this point in the history
  • Loading branch information
luzrain committed Sep 27, 2024
1 parent f88f99e commit d85b1c3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
6 changes: 2 additions & 4 deletions src/Internal/MasterProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function __construct(
$this->socketFile = \sprintf('%s/phpss%s.socket', $runDirectory, \hash('xxh32', $this->startFile . 'rx'));

$this->supervisor = new Supervisor($this, $stopTimeout, $this->status);
$this->scheduler = new Scheduler();
$this->scheduler = new Scheduler($this->status);
$this->container = new ArrayContainer();
}

Expand Down Expand Up @@ -129,9 +129,7 @@ public function run(bool $daemonize = false): int
$this->saveMasterPid();
$this->start();
$this->supervisor->start($this->suspension);
$this->scheduler->start($this->logger, $this->suspension, function () {
return $this->status;
});
$this->scheduler->start($this->suspension, $this->logger);
$this->status = Status::RUNNING;
$this->logger->info(Server::NAME . ' has started');

Expand Down
20 changes: 6 additions & 14 deletions src/Internal/Scheduler/Scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ final class Scheduler
private WorkerPool $pool;
private LoggerInterface $logger;
private Suspension $suspension;
/** @var \Closure(): Status */
private \Closure $status;
private DeferredFuture|null $stopFuture = null;

public function __construct()
public function __construct(private Status &$status)
{
$this->pool = new WorkerPool();
}
Expand All @@ -36,17 +34,10 @@ public function addWorker(PeriodicProcessInterface $worker): void
$this->pool->addWorker($worker);
}

/**
* @param \Closure(): Status $status
*/
public function start(
LoggerInterface $logger,
Suspension $suspension,
\Closure $status,
): void {
$this->logger = $logger;
public function start(Suspension $suspension, LoggerInterface $logger): void
{
$this->suspension = $suspension;
$this->status = $status;
$this->logger = $logger;

SIGCHLDHandler::onChildProcessExit(weakClosure($this->onChildStop(...)));

Expand All @@ -65,12 +56,13 @@ public function start(

private function scheduleWorker(PeriodicProcessInterface $worker, TriggerInterface $trigger): bool
{
if (($this->status)() !== Status::RUNNING) {
if ($this->status !== Status::RUNNING) {
return false;
}

$currentDate = new \DateTimeImmutable();
$nextRunDate = $trigger->getNextRunDate($currentDate);

if ($nextRunDate !== null) {
$delay = $nextRunDate->getTimestamp() - $currentDate->getTimestamp();
EventLoop::delay($delay, fn() => $this->startWorker($worker, $trigger));
Expand Down

0 comments on commit d85b1c3

Please sign in to comment.