An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
feat: enhance horizon:manage command with worker restart check
Andras Bacsaia3648901ed88
diff --git a/app/Console/Commands/HorizonManage.php b/app/Console/Commands/HorizonManage.phpindex a03c41a7ba..de4a5a2642 100644--- a/app/Console/Commands/HorizonManage.php+++ b/app/Console/Commands/HorizonManage.php@@ -2,6 +2,7 @@namespace App\Console\Commands;+use App\Models\ApplicationDeploymentQueue;use App\Repositories\CustomJobRepository;use Illuminate\Console\Command;use Illuminate\Support\Facades\Artisan;@@ -15,17 +16,21 @@ use function Laravel\Prompts\table;class HorizonManage extends Command{- protected $signature = 'horizon:manage';+ protected $signature = 'horizon:manage {--can-i-restart-this-worker}';protected $description = 'Manage horizon';public function handle(){+ if ($this->option('can-i-restart-this-worker')) {+ return $this->canIRestartThisWorker();+ }$action = select(label: 'What to do?',options: ['pending' => 'Pending Jobs','running' => 'Running Jobs',+ 'can-i-restart-this-worker' => 'Can I restart this worker?','workers' => 'Workers','failed' => 'Failed Jobs','failed-delete' => 'Failed Jobs - Delete',@@ -33,6 +38,16 @@ class HorizonManage extends Command]);+ if ($action === 'can-i-restart-this-worker') {+ $runningJobs = ApplicationDeploymentQueue::where('horizon_job_worker', gethostname())->where('horizon_job_status', 'reserved')->get();+ $count = $runningJobs->count();+ if ($count > 0) {+ return false;+ }++ return true;+ }+if ($action === 'pending') {$pendingJobs = app(JobRepository::class)->getPending();$pendingJobsTable = [];@@ -136,4 +151,15 @@ class HorizonManage extends Command$redisJobRepository->purge($queueName);}}++ public function canIRestartThisWorker()+ {+ $runningJobs = ApplicationDeploymentQueue::where('horizon_job_worker', gethostname())->where('horizon_job_status', 'reserved')->get();+ $count = $runningJobs->count();+ if ($count > 0) {+ return false;+ }++ return true;+ }}diff --git a/app/Repositories/CustomJobRepository.php b/app/Repositories/CustomJobRepository.phpindex 3d67cdd1a9..518be844f6 100644--- a/app/Repositories/CustomJobRepository.php+++ b/app/Repositories/CustomJobRepository.php@@ -31,7 +31,6 @@ class CustomJobRepository extends RedisJobRepository implements CustomJobReposit$this->getRecent()->each(function ($job) use ($jobs, $status, $worker) {if ($job->status === $status) {if ($worker) {- dump($job);if ($job->worker !== $worker) {return;}