Skip to content

Commit

Permalink
refactor: enhance ApplicationDeploymentJob and HorizonServiceProvider…
Browse files Browse the repository at this point in the history
… for improved job handling

- Removed the private property for application deployment queue ID in ApplicationDeploymentJob and utilized constructor property promotion.
- Added a tags method in ApplicationDeploymentJob to properly identify the worker running the job.
- Updated HorizonServiceProvider to handle cases where the deployment queue ID is blank, preventing potential errors during job processing.
- Cleaned up the isAnyDeploymentInprogress function by removing unnecessary whitespace.
  • Loading branch information
andrasbacsai committed Jan 10, 2025
1 parent 7582d7d commit 3a32193
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
13 changes: 8 additions & 5 deletions app/Jobs/ApplicationDeploymentJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions app/Providers/HorizonServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public function boot(): void
$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([
Expand Down
1 change: 0 additions & 1 deletion bootstrap/helpers/shared.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3a32193

Please sign in to comment.