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: improve deployment status check in isAnyDeploymentInprogress function

Andras Bacsaidb079c0c7d4d
diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php
index 74220a1f90..17e17b7fa9 100644
--- a/bootstrap/helpers/shared.php
+++ b/bootstrap/helpers/shared.php
@@ -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)
diff --git a/scripts/cloud_upgrade.sh b/scripts/cloud_upgrade.sh
index 8bab73b986..4cb326cbb0 100644
--- a/scripts/cloud_upgrade.sh
+++ b/scripts/cloud_upgrade.sh
@@ -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
\ No newline at end of file