@@ -17,7 +17,8 @@ class PurgeCommand extends Command
17
17
*
18
18
* @var string
19
19
*/
20
- protected $ signature = 'horizon:purge ' ;
20
+ protected $ signature = 'horizon:purge
21
+ {--signal=SIGTERM : The signal to send to the rogue processes} ' ;
21
22
22
23
/**
23
24
* The console command description.
@@ -69,9 +70,13 @@ public function __construct(
69
70
*/
70
71
public function handle (MasterSupervisorRepository $ masters )
71
72
{
73
+ $ signal = is_numeric ($ signal = $ this ->option ('signal ' ))
74
+ ? $ signal
75
+ : constant ($ signal );
76
+
72
77
foreach ($ masters ->names () as $ master ) {
73
78
if (Str::startsWith ($ master , MasterSupervisor::basename ())) {
74
- $ this ->purge ($ master );
79
+ $ this ->purge ($ master, $ signal );
75
80
}
76
81
}
77
82
}
@@ -80,11 +85,12 @@ public function handle(MasterSupervisorRepository $masters)
80
85
* Purge any orphan processes.
81
86
*
82
87
* @param string $master
88
+ * @param int $signal
83
89
* @return void
84
90
*/
85
- public function purge ($ master )
91
+ public function purge ($ master, $ signal = SIGTERM )
86
92
{
87
- $ this ->recordOrphans ($ master );
93
+ $ this ->recordOrphans ($ master, $ signal );
88
94
89
95
$ expired = $ this ->processes ->orphanedFor (
90
96
$ master , $ this ->supervisors ->longestActiveTimeout ()
@@ -93,7 +99,7 @@ public function purge($master)
93
99
collect ($ expired )->each (function ($ processId ) use ($ master ) {
94
100
$ this ->comment ("Killing Process: {$ processId }" );
95
101
96
- exec ("kill {$ processId }" );
102
+ exec ("kill -s { $ signal } {$ processId }" );
97
103
98
104
$ this ->processes ->forgetOrphans ($ master , [$ processId ]);
99
105
});
@@ -103,9 +109,10 @@ public function purge($master)
103
109
* Record the orphaned Horizon processes.
104
110
*
105
111
* @param string $master
112
+ * @param int $signal
106
113
* @return void
107
114
*/
108
- protected function recordOrphans ($ master )
115
+ protected function recordOrphans ($ master, $ signal )
109
116
{
110
117
$ this ->processes ->orphaned (
111
118
$ master , $ orphans = $ this ->inspector ->orphaned ()
@@ -114,7 +121,7 @@ protected function recordOrphans($master)
114
121
foreach ($ orphans as $ processId ) {
115
122
$ this ->info ("Observed Orphan: {$ processId }" );
116
123
117
- if (! posix_kill ($ processId , SIGTERM )) {
124
+ if (! posix_kill ($ processId , $ signal )) {
118
125
$ this ->error ("Failed to kill process for Orphan: {$ processId } ( " .posix_strerror (posix_get_last_error ()).') ' );
119
126
}
120
127
}
0 commit comments