Skip to content

Commit

Permalink
refactor: improve deployment status check in isAnyDeploymentInprogres…
Browse files Browse the repository at this point in the history
…s function

- Updated the isAnyDeploymentInprogress function to check for running jobs based on the current hostname.
- Enhanced the logic to return true if any job status is 'unknown' and to provide a clearer output regarding the number of deployments in progress.
- Modified the cloud_upgrade.sh script to loop until the deployment status check confirms no ongoing deployments before proceeding with the upgrade.
  • Loading branch information
andrasbacsai committed Jan 10, 2025
1 parent 02400ad commit db079c0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
25 changes: 17 additions & 8 deletions bootstrap/helpers/shared.php
Original file line number Diff line number Diff line change
Expand Up @@ -1258,14 +1258,23 @@ function get_public_ips()

function isAnyDeploymentInprogress()
{
// Only use it in the deployment script
$count = ApplicationDeploymentQueue::whereIn('status', [ApplicationDeploymentStatus::IN_PROGRESS, ApplicationDeploymentStatus::QUEUED])->count();
if ($count > 0) {
echo "There are $count deployments in progress. Exiting...\n";
exit(1);
}
echo "No deployments in progress.\n";
exit(0);

$runningJobs = ApplicationDeploymentQueue::where('horizon_job_worker', gethostname())->where('status', ApplicationDeploymentStatus::IN_PROGRESS->value)->get();
$horizonJobIds = [];
foreach ($runningJobs as $runningJob) {
$horizonJobId = getJobStatus($runningJob->horizon_job_id);
if ($horizonJobId === 'unknown') {
return true;
}
$horizonJobIds[] = $runningJob->horizon_job_id;
}
if (count($horizonJobIds) === 0) {
echo "No deployments in progress.\n";
exit(0);
}
$horizonJobIds = collect($horizonJobIds)->unique()->toArray();
echo 'There are '.count($horizonJobIds)." deployments in progress.\n";
exit(1);
}

function isBase64Encoded($strValue)
Expand Down
5 changes: 1 addition & 4 deletions scripts/cloud_upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@ export IMAGE=$1
docker system prune -af
docker compose pull
read -p "Press Enter to update Coolify to $IMAGE..." </dev/tty
docker exec coolify sh -c "php artisan tinker --execute='isAnyDeploymentInprogress()'"
docker compose up --remove-orphans --force-recreate -d --wait
echo $IMAGE > last_version
docker compose logs -f
while ! (docker exec coolify sh -c "php artisan tinker --execute='isAnyDeploymentInprogress()'" && docker compose up --remove-orphans --force-recreate -d --wait && echo $IMAGE > last_version); do sleep 1; done

0 comments on commit db079c0

Please sign in to comment.