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
fix(queues): run service restarts and proxy start/restart on the deployments queue
Andras Bacsai80b8b219a26c
diff --git a/app/Actions/Proxy/StartProxy.php b/app/Actions/Proxy/StartProxy.phpindex 3508a46302..169064e180 100644--- a/app/Actions/Proxy/StartProxy.php+++ b/app/Actions/Proxy/StartProxy.php@@ -8,12 +8,18 @@ use App\Events\ProxyStatusChangedUI;use App\Models\Server;use App\Services\ProxyPortParser;use Lorisleiva\Actions\Concerns\AsAction;+use Lorisleiva\Actions\Decorators\JobDecorator;use Spatie\Activitylog\Models\Activity;class StartProxy{use AsAction;+ public function configureJob(JobDecorator $job): void+ {+ $job->onQueue(deployment_queue());+ }+public function handle(Server $server, bool $async = true, bool $force = false, bool $restarting = false): string|Activity{$proxyType = $server->proxyType();@@ -87,7 +93,7 @@ class StartProxy}if ($async) {- return remote_process($commands, $server, callEventOnFinish: 'ProxyStatusChanged', callEventData: $server->id);+ return remote_process($commands, $server, callEventOnFinish: 'ProxyStatusChanged', callEventData: $server->id, queue: deployment_queue());} else {instant_remote_process($commands, $server);diff --git a/app/Actions/Service/RestartService.php b/app/Actions/Service/RestartService.phpindex 6acd3b0a43..4092fb3176 100644--- a/app/Actions/Service/RestartService.php+++ b/app/Actions/Service/RestartService.php@@ -4,12 +4,16 @@ namespace App\Actions\Service;use App\Models\Service;use Lorisleiva\Actions\Concerns\AsAction;+use Lorisleiva\Actions\Decorators\JobDecorator;class RestartService{use AsAction;- public string $jobQueue = 'high';+ public function configureJob(JobDecorator $job): void+ {+ $job->onQueue(deployment_queue());+ }public function handle(Service $service, bool $pullLatestImages){diff --git a/app/Actions/Service/RestartServiceApplication.php b/app/Actions/Service/RestartServiceApplication.phpindex ebee6e2f27..94c06ca653 100644--- a/app/Actions/Service/RestartServiceApplication.php+++ b/app/Actions/Service/RestartServiceApplication.php@@ -5,12 +5,16 @@ namespace App\Actions\Service;use App\Models\ServiceApplication;use App\Models\ServiceDatabase;use Lorisleiva\Actions\Concerns\AsAction;+use Lorisleiva\Actions\Decorators\JobDecorator;class RestartServiceApplication{use AsAction;- public string $jobQueue = 'high';+ public function configureJob(JobDecorator $job): void+ {+ $job->onQueue(deployment_queue());+ }public function handle(ServiceApplication|ServiceDatabase $serviceApplication): void{diff --git a/app/Jobs/RestartProxyJob.php b/app/Jobs/RestartProxyJob.phpindex b74d8f83a7..c99cf9d9eb 100644--- a/app/Jobs/RestartProxyJob.php+++ b/app/Jobs/RestartProxyJob.php@@ -31,7 +31,10 @@ class RestartProxyJob implements ShouldBeEncrypted, ShouldQueuereturn [(new WithoutOverlapping('restart-proxy-'.$this->server->uuid))->expireAfter(120)->dontRelease()];}- public function __construct(public Server $server) {}+ public function __construct(public Server $server)+ {+ $this->onQueue(deployment_queue());+ }public function handle(){@@ -56,7 +59,8 @@ class RestartProxyJob implements ShouldBeEncrypted, ShouldQueue$commands,$this->server,callEventOnFinish: 'ProxyStatusChanged',- callEventData: $this->server->id+ callEventData: $this->server->id,+ queue: deployment_queue(),);// Store activity ID and notify UI immediately with itdiff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.phpindex eccba95fd1..7494787459 100644--- a/bootstrap/helpers/shared.php+++ b/bootstrap/helpers/shared.php@@ -1021,7 +1021,8 @@ function isCloud(): bool}/**- * Resolve the queue used for application deployments, database starts and service starts.+ * Resolve the queue used for application deployments and for database, service and proxy+ * starts and restarts.** On cloud these jobs run on a dedicated `deployments` queue so they can be drained by an* isolated Horizon worker pool; self-hosted keeps them on the shared `high` queue. Routingdiff --git a/tests/Feature/QueueRoutingTest.php b/tests/Feature/QueueRoutingTest.phpindex 717b4a5b41..98c4f3123e 100644--- a/tests/Feature/QueueRoutingTest.php+++ b/tests/Feature/QueueRoutingTest.php@@ -3,10 +3,15 @@use App\Actions\Database\RestartDatabase;use App\Actions\Database\StartDatabase;use App\Actions\Database\StartDatabaseProxy;+use App\Actions\Proxy\StartProxy;+use App\Actions\Service\RestartService;+use App\Actions\Service\RestartServiceApplication;use App\Actions\Service\StartService;use App\Jobs\DatabaseBackupJob;+use App\Jobs\RestartProxyJob;use App\Jobs\ScheduledJobManager;use App\Models\ScheduledDatabaseBackup;+use App\Models\Server;describe('deployment_queue helper', function () {test('uses the high queue on self-hosted', function () {@@ -46,6 +51,9 @@ describe('start action job routing', function () {RestartDatabase::class,StartDatabaseProxy::class,StartService::class,+ RestartService::class,+ RestartServiceApplication::class,+ StartProxy::class,]);test('routes to the high queue on self-hosted', function (string $actionClass) {@@ -57,9 +65,26 @@ describe('start action job routing', function () {RestartDatabase::class,StartDatabaseProxy::class,StartService::class,+ RestartService::class,+ RestartServiceApplication::class,+ StartProxy::class,]);});+describe('proxy restart job routing', function () {+ test('routes to the deployments queue on cloud', function () {+ config(['constants.coolify.self_hosted' => false]);++ expect((new RestartProxyJob(new Server))->queue)->toBe('deployments');+ });++ test('routes to the high queue on self-hosted', function () {+ config(['constants.coolify.self_hosted' => true]);++ expect((new RestartProxyJob(new Server))->queue)->toBe('high');+ });+});+describe('scheduled job routing', function () {test('scheduled jobs use the crons queue on cloud', function () {config(['constants.coolify.self_hosted' => false]);