Two deploys of the same app start a few seconds apart. One uploads the new build, the other uploads an older one on top. Or one runs a database migration while the other is still serving the old schema. The site ends up in a state nobody released.
This happens more often once coding agents can deploy. Two agents finish their tasks at the same time, and each one runs the deploy script. A second, related problem: a deploy that is stopped halfway, by a closed laptop, a killed terminal or a time limit, can leave the site half old and half new.
Why concurrent deploys break things
Most deploy steps are not safe to run twice at once. Uploading files, switching a symlink, running migrations, purging a cache and updating a config all assume they are the only deploy running. Two of them interleaved can:
- leave the older build live, even though the newer one "succeeded";
- run a migration twice, or run it against the wrong code;
- make a rollback restore the wrong version, because the "previous release" changed under it.
In CI: use what your CI already has
If you deploy from a CI service, use its own lock. GitHub Actions has concurrency groups, which let one deploy run at a time per group. By default a group keeps only one run waiting and cancels an older waiting run when a newer one arrives; queue: max keeps up to 100 waiting, in order. GitLab has resource_group for the same purpose. Many deploy platforms queue their own deploys. These are the right tools when every deploy goes through CI.
The gap is deploys that start from a developer machine: a person running a script, or agents running it for them.
Without any extra tool
- One deploy command, one lock. Wrap the deploy script with
flockon Linux, for exampleflock -n /tmp/web-app-deploy.lock ./deploy.sh, so a second start fails at once instead of running. macOS has noflockcommand, but it shipslockf, which does the same:lockf -t 0 /tmp/web-app-deploy.lock ./deploy.sh. - Deploy one commit, from a clean tree. Refuse to deploy when
git status --porcelainprints anything. - Make the switch atomic. Upload the new build beside the old one and switch with one step at the end (a symlink, a load balancer target, a new version label). Then a cut-off upload leaves the old version live.
- Keep a rollback command that you have tried, and a health check that tells you which version is live.
- Do not interrupt a running deploy. Stopping halfway is often worse than letting it finish and rolling back.
How dotime-queue release helps
dotime-queue release runs one release of a repository as one queued job. The steps come from a file you commit, dotime.release.json: checks, a security check, an optional review, a build, then your deploy, verify and rollback commands. Only deploy is required.
dotime-queue release --dry-rundotime-queue releasedotime-queue releasesOne release per repository. Before anything runs, the release takes a claim for its repository, a file in the queue's state folder that only one process can create. The main checkout and every git worktree of it count as one repository, so two agents in two worktrees cannot both release. A second release while one runs is refused with exit 5, nothing deployed, and the message names the processes that hold the claim.
The claim outlives a dead runner. The claim stays held while the release process, the release job or the step it runs is alive. If the release process dies while the deploy runs, the deploy keeps the claim until it ends, so no new release starts on top of it.
Not started without time to finish. A release is refused before its deploy when less of its run limit is left than the deploy, the rollback and the verify steps may need.
A deploy cut off is left to finish. When the release process dies during the deploy, the queue does not pass the stop on to the deploy. A deploy stopped halfway is the worst state to leave a live target in. A stop you send while the release process lives, such as Ctrl-C, does stop the deploy, and then the rollback runs when one is set.
Honest outcomes. Each release ends with an exit code and a line in the release log:
| Exit | Outcome | Meaning |
|---|---|---|
| 0 | released | Deployed, and verified when verify is set. |
| 5 | refused | Stopped before the deploy. Nothing was deployed. |
| 6 | rolled-back | The deploy or verify failed; the rollback ran and verify passed after it. |
| 7 | not-restored or unknown | The previous release could not be put back, or the release died after its deploy began. The live state may be broken. |
A release that died mid-deploy is shown as unknown, never as a success. dotime-queue releases lists the history, newest first. Before releasing again after an unknown, look at the live site.
If you must stop a release, stop it while it is still waiting in line. dotime-queue cancel <pid> then ends it with exit 5 and nothing deployed.
What it does not do
- It only covers releases started through
dotime-queue releaseon one computer. A deploy someone runs directly, a deploy from CI, or a deploy from another machine is not held by the claim. - A separate clone of the same project is another repository to the queue, with its own claim. Use worktrees of one clone, or deploy from one place.
- It has no deploy targets of its own and does not host apps. It runs the deploy, verify and rollback commands you write.
- It cannot undo a provider's half-finished state by itself. It runs your rollback command, and only when there is a previous release to go back to.
- The claim is cooperative. Any process running as you can remove the file or deploy without the queue.