Skip to content

Commit

Permalink
Add event for when supervisor process died
Browse files Browse the repository at this point in the history
  • Loading branch information
frankprins committed Jun 13, 2023
1 parent 48e842d commit a67025e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/Events/SupervisorProcessDied.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Laravel\Horizon\Events;

use Laravel\Horizon\SupervisorProcess;

class SupervisorProcessDied
{
/**
* The supervisor process.
*
* @var \Laravel\Horizon\SupervisorProcess
*/
public $supervisorProcess;

/**
* The code with which the process exited.
*
* @var int|null
*/
public $exitCode;

/**
* Create a new event instance.
*
* @param \Laravel\Horizon\SupervisorProcess $supervisorProcess
* @param int|null $exitCode
* @return void
*/
public function __construct(SupervisorProcess $supervisorProcess, ?int $exitCode)
{
$this->supervisorProcess = $supervisorProcess;
$this->exitCode = $exitCode;
}
}
4 changes: 4 additions & 0 deletions src/SupervisorProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Laravel\Horizon\Contracts\HorizonCommandQueue;
use Laravel\Horizon\Events\SupervisorProcessDied;
use Laravel\Horizon\MasterSupervisorCommands\AddSupervisor;
use Laravel\Horizon\SupervisorCommands\Terminate;

Expand Down Expand Up @@ -77,6 +78,8 @@ public function monitor()
// other checks run because we do not care if this is cooling down here.
if (! $this->process->isRunning() &&
$this->process->getExitCode() === 13) {
event(new SupervisorProcessDied($this, $this->process->getExitCode()));

return $this->markAsDead();
}

Expand All @@ -92,6 +95,7 @@ public function monitor()
// should be marked as dead and not be restarted. Typically, this could be
// an indication that the supervisor was simply purposefully terminated.
$exitCode = $this->process->getExitCode();
event(new SupervisorProcessDied($this, $exitCode));

$this->markAsDead();

Expand Down

0 comments on commit a67025e

Please sign in to comment.