Skip to content

Commit

Permalink
Merge pull request #22 from joelvh/hotfix/forward-signals
Browse files Browse the repository at this point in the history
Forward signal to process
  • Loading branch information
freekmurze committed Oct 24, 2023
2 parents dec3cea + 78a7c89 commit 95c17b0
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/Commands/WatchHorizonCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ public function handle()
{
$this->components->info('Starting Horizon and will restart it when any files change...');

$this->trap([SIGINT, SIGTERM], function ($signal): void {
$this->trappedSignal = $signal;
});

$horizonStarted = $this->startHorizon();

if (! $horizonStarted) {
if (! $this->startHorizon()) {
return Command::FAILURE;
}

Expand All @@ -35,9 +29,17 @@ public function handle()

protected function startHorizon(): bool
{
$this->horizonProcess = Process::fromShellCommandline(config('horizon-watcher.command'));
$this->horizonProcess = Process::fromShellCommandline(config('horizon-watcher.command'))
->setTty(! $this->option('without-tty'))
->setTimeout(null);

$this->horizonProcess->setTty(! $this->option('without-tty'))->setTimeout(null);
$this->trap([SIGINT, SIGTERM, SIGQUIT], function ($signal): void {
$this->trappedSignal = $signal;

// Forward signal to Horizon process.
$this->horizonProcess->stop(signal: $signal);
$this->horizonProcess->wait();
});

$this->horizonProcess->start(fn ($type, $output) => $this->info($output));

Expand Down Expand Up @@ -82,6 +84,7 @@ protected function restartHorizon(): self
$this->components->info('Change detected! Restarting horizon...');

$this->horizonProcess->stop();
$this->horizonProcess->wait();

$this->startHorizon();

Expand Down

0 comments on commit 95c17b0

Please sign in to comment.