8000 Add signal option to `horizon:purge` (e.g. `SIGKILL`) (#1226) · laravel/horizon@22b6d7c · GitHub
[go: up one dir, main page]

Skip to content

Commit 22b6d7c

Browse files
Add signal option to horizon:purge (e.g. SIGKILL) (#1226)
* add signal option (e.g. SIGKILL) * formatting Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 65cf61c commit 22b6d7c

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/Console/PurgeCommand.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class PurgeCommand extends Command
1717
*
1818
* @var string
1919
*/
20-
protected $signature = 'horizon:purge';
20+
protected $signature = 'horizon:purge
21+
{--signal=SIGTERM : The signal to send to the rogue processes}';
2122

2223
/**
2324
* The console command description.
@@ -69,9 +70,13 @@ public function __construct(
6970
*/
7071
public function handle(MasterSupervisorRepository $masters)
7172
{
73+
$signal = is_numeric($signal = $this->option('signal'))
74+
? $signal
75+
: constant($signal);
76+
7277
foreach ($masters->names() as $master) {
7378
if (Str::startsWith($master, MasterSupervisor::basename())) {
74-
$this->purge($master);
79+
$this->purge($master, $signal);
7580
}
7681
}
7782
}
@@ -80,11 +85,12 @@ public function handle(MasterSupervisorRepository $masters)
8085
* Purge any orphan processes.
8186
*
8287
* @param string $master
88+
* @param int $signal
8389
* @return void
8490
*/
85-
public function purge($master)
91+
public function purge($master, $signal = SIGTERM)
8692
{
87-
$this->recordOrphans($master);
93+
$this->recordOrphans($master, $signal);
8894

8995
$expired = $this->processes->orphanedFor(
9096
$master, $this->supervisors->longestActiveTimeout()
@@ -93,7 +99,7 @@ public function purge($master)
9399
collect($expired)->each(function ($processId) use ($master) {
94100
$this->comment("Killing Process: {$processId}");
95101

96-
exec("kill {$processId}");
102+
exec("kill -s {$signal} {$processId}");
97103

98104
$this->processes->forgetOrphans($master, [$processId]);
99105
});
@@ -103,9 +109,10 @@ public function purge($master)
103109
* Record the orphaned Horizon processes.
104110
*
105111
* @param string $master
112+
* @param int $signal
106113
* @return void
107114
*/
108-
protected function recordOrphans($master)
115+
protected function recordOrphans($master, $signal)
109116
{
110117
$this->processes->orphaned(
111118
$master, $orphans = $this->inspector->orphaned()
@@ -114,7 +121,7 @@ protected function recordOrphans($master)
114121
foreach ($orphans as $processId) {
115122
$this->info("Observed Orphan: {$processId}");
116123

117-
if (! posix_kill($processId, SIGTERM)) {
124+
if (! posix_kill($processId, $signal)) {
118125
$this->error("Failed to kill process for Orphan: {$processId} (".posix_strerror(posix_get_last_error()).')');
119126
}
120127
}

0 commit comments

Comments
 (0)
0