refactor: enhance ApplicationDeploymentJob and HorizonServiceProvider 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.
This commit is contained in:
@@ -43,8 +43,6 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
|
|||||||
|
|
||||||
public static int $batch_counter = 0;
|
public static int $batch_counter = 0;
|
||||||
|
|
||||||
private int $application_deployment_queue_id;
|
|
||||||
|
|
||||||
private bool $newVersionIsHealthy = false;
|
private bool $newVersionIsHealthy = false;
|
||||||
|
|
||||||
private ApplicationDeploymentQueue $application_deployment_queue;
|
private ApplicationDeploymentQueue $application_deployment_queue;
|
||||||
@@ -166,16 +164,21 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
|
|||||||
|
|
||||||
public $tries = 1;
|
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->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->application = Application::find($this->application_deployment_queue->application_id);
|
||||||
$this->build_pack = data_get($this->application, 'build_pack');
|
$this->build_pack = data_get($this->application, 'build_pack');
|
||||||
$this->build_args = collect([]);
|
$this->build_args = collect([]);
|
||||||
|
|
||||||
$this->application_deployment_queue_id = $application_deployment_queue_id;
|
|
||||||
$this->deployment_uuid = $this->application_deployment_queue->deployment_uuid;
|
$this->deployment_uuid = $this->application_deployment_queue->deployment_uuid;
|
||||||
$this->pull_request_id = $this->application_deployment_queue->pull_request_id;
|
$this->pull_request_id = $this->application_deployment_queue->pull_request_id;
|
||||||
$this->commit = $this->application_deployment_queue->commit;
|
$this->commit = $this->application_deployment_queue->commit;
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ class HorizonServiceProvider extends HorizonApplicationServiceProvider
|
|||||||
$deploymentQueueId = collect($tags)->first(function ($tag) {
|
$deploymentQueueId = collect($tags)->first(function ($tag) {
|
||||||
return str_contains($tag, 'App\Models\ApplicationDeploymentQueue');
|
return str_contains($tag, 'App\Models\ApplicationDeploymentQueue');
|
||||||
});
|
});
|
||||||
|
if (blank($deploymentQueueId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$deploymentQueueId = explode(':', $deploymentQueueId)[1];
|
$deploymentQueueId = explode(':', $deploymentQueueId)[1];
|
||||||
$deploymentQueue = ApplicationDeploymentQueue::find($deploymentQueueId);
|
$deploymentQueue = ApplicationDeploymentQueue::find($deploymentQueueId);
|
||||||
$deploymentQueue->update([
|
$deploymentQueue->update([
|
||||||
|
|||||||
@@ -1258,7 +1258,6 @@ function get_public_ips()
|
|||||||
|
|
||||||
function isAnyDeploymentInprogress()
|
function isAnyDeploymentInprogress()
|
||||||
{
|
{
|
||||||
|
|
||||||
$runningJobs = ApplicationDeploymentQueue::where('horizon_job_worker', gethostname())->where('status', ApplicationDeploymentStatus::IN_PROGRESS->value)->get();
|
$runningJobs = ApplicationDeploymentQueue::where('horizon_job_worker', gethostname())->where('status', ApplicationDeploymentStatus::IN_PROGRESS->value)->get();
|
||||||
$horizonJobIds = [];
|
$horizonJobIds = [];
|
||||||
foreach ($runningJobs as $runningJob) {
|
foreach ($runningJobs as $runningJob) {
|
||||||
|
|||||||
Reference in New Issue
Block a user