Skip to content

Commit

Permalink
Create command and register it
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphjsmit committed Sep 25, 2021
1 parent 2551d4b commit 63093f1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
33 changes: 33 additions & 0 deletions src/LaravelHorizonCron/Console/RestartHorizon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace RalphJSmit\LaravelHorizonCron\Supervisor\Console;

use Illuminate\Console\Command;

class RestartHorizon extends Command
{
protected $signature = 'supervisor:check';

protected $description = 'Checks if Horizon is running, starts the queue if needed.';

/**
* The command the actually performs the logic
*/
public function handle()
{
$res = shell_exec("php artisan horizon:status");

if($res !== "Horizon is running.\n") {
echo "horizon is not running, starting it\n";
$fp = popen("php artisan horizon", "r");
while (!feof($fp)) {
$buffer = fgets($fp, 4096);
echo $buffer;
}
echo "horizon was terminated\n";
pclose($fp);
} else {
echo "horizon is running\n";
}
}
}
4 changes: 3 additions & 1 deletion src/LaravelHorizonCron/SupervisorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ class SupervisorServiceProvider extends ServiceProvider
{
public function boot()
{
//
$this->commands([
\RalphJSmit\LaravelHorizonCron\Supervisor\Console\RestartHorizon::class,
]);
}

public function register()
Expand Down

0 comments on commit 63093f1

Please sign in to comment.