Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add event for when supervisor process died #1284

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/Events/SupervisorProcessDied.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

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