Skip to content

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.

refactor: enhance ApplicationDeploymentJob and HorizonServiceProvider for improved job handling

Andras Bacsai3a3219394d18
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php
index 3092016531..538c2eca08 100644
--- a/app/Jobs/ApplicationDeploymentJob.php
+++ b/app/Jobs/ApplicationDeploymentJob.php
@@ -43,8 +43,6 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
public static int $batch_counter = 0;
- private int $application_deployment_queue_id;
-
private bool $newVersionIsHealthy = false;
private ApplicationDeploymentQueue $application_deployment_queue;
@@ -166,16 +164,21 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
public $tries = 1;
- public function __construct(int $application_deployment_queue_id)
+ public function tags()
+ {
+ // Do not remove this one, it needs to properly identify which worker is running the job
+ return ['App\Models\ApplicationDeploymentQueue:'.$this->application_deployment_queue_id];
+ }
+
+ public function __construct(public int $application_deployment_queue_id)
{
$this->onQueue('high');
- $this->application_deployment_queue = ApplicationDeploymentQueue::find($application_deployment_queue_id);
+ $this->application_deployment_queue = ApplicationDeploymentQueue::find($this->application_deployment_queue_id);
$this->application = Application::find($this->application_deployment_queue->application_id);
$this->build_pack = data_get($this->application, 'build_pack');
$this->build_args = collect([]);
- $this->application_deployment_queue_id = $application_deployment_queue_id;
$this->deployment_uuid = $this->application_deployment_queue->deployment_uuid;
$this->pull_request_id = $this->application_deployment_queue->pull_request_id;
$this->commit = $this->application_deployment_queue->commit;
diff --git a/app/Providers/HorizonServiceProvider.php b/app/Providers/HorizonServiceProvider.php
index 2a459e74af..0caa3a3a93 100644
--- a/app/Providers/HorizonServiceProvider.php
+++ b/app/Providers/HorizonServiceProvider.php
@@ -38,6 +38,9 @@ class HorizonServiceProvider extends HorizonApplicationServiceProvider
$deploymentQueueId = collect($tags)->first(function ($tag) {
return str_contains($tag, 'App\Models\ApplicationDeploymentQueue');
});
+ if (blank($deploymentQueueId)) {
+ return;
+ }
$deploymentQueueId = explode(':', $deploymentQueueId)[1];
$deploymentQueue = ApplicationDeploymentQueue::find($deploymentQueueId);
$deploymentQueue->update([
diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php
index fd7e63b75f..32b7463def 100644
--- a/bootstrap/helpers/shared.php
+++ b/bootstrap/helpers/shared.php
@@ -1258,7 +1258,6 @@ function get_public_ips()
function isAnyDeploymentInprogress()
{
-
$runningJobs = ApplicationDeploymentQueue::where('horizon_job_worker', gethostname())->where('status', ApplicationDeploymentStatus::IN_PROGRESS->value)->get();
$horizonJobIds = [];
foreach ($runningJobs as $runningJob) {