@@ -36,7 +36,7 @@ class TerminateCommand extends Command
3636 *
3737 * @param \Illuminate\Contracts\Cache\Factory $cache
3838 * @param \Laravel\Horizon\Contracts\MasterSupervisorRepository $masters
39- * @return void
39+ * @return int|null
4040 */
4141 public function handle (CacheFactory $ cache , MasterSupervisorRepository $ masters )
4242 {
@@ -50,10 +50,16 @@ public function handle(CacheFactory $cache, MasterSupervisorRepository $masters)
5050 ->filter (fn ($ master ) => Str::startsWith ($ master ->name , MasterSupervisor::basename ()))
5151 ->all ();
5252
53- collect (Arr::pluck ($ masters , 'pid ' ))
53+ $ exitCode = null ;
54+
55+ $ result = collect (Arr::pluck ($ masters , 'pid ' ))
5456 ->whenNotEmpty (fn () => $ this ->components ->info ('Sending TERM signal to processes. ' ))
55- ->whenEmpty (fn () => $ this ->components ->info ('No processes to terminate. ' ))
56- ->each (function ($ processId ) {
57+ ->whenEmpty (function () use (&$ exitCode ) {
58+ $ this ->components ->info ('No processes to terminate. ' );
59+
60+ $ exitCode = Command::FAILURE ;
61+ })
62+ ->each (function ($ processId ) use (&$ exitCode ) {
5763 $ result = true ;
5864
5965 $ this ->components ->task ("Process: $ processId " , function () use ($ processId , &$ result ) {
@@ -62,9 +68,17 @@ public function handle(CacheFactory $cache, MasterSupervisorRepository $masters)
6268
6369 if (! $ result ) {
6470 $ this ->components ->error ("Failed to kill process: {$ processId } ( " .posix_strerror (posix_get_last_error ()).') ' );
71+
72+ $ exitCode = Command::FAILURE ;
73+ } else if ($ exitCode === null ) {
74+ $ exitCode = Command::SUCCESS ;
6575 }
6676 })->whenNotEmpty (fn () => $ this ->output ->writeln ('' ));
6777
78+
79+
6880 $ this ->laravel ['cache ' ]->forever ('illuminate:queue:restart ' , $ this ->currentTime ());
81+
82+ return $ exitCode ?? Command::SUCCESS ;
6983 }
7084}
0 commit comments