Path in the Gestor bibliotecas/deploy-lock.php
Per-environment deploy lock (req-197). A lock file prevents two deploys at the same time in the same environment. Users:
-
the system update (
temp/deploy.lock, CLI and web); -
the API project deploy (same file; refuses with HTTP 409);
-
the
c2f project:update-allpipeline (per-target lock inGIT/.c2f-deploy-locks/, with waiting).
The library is pure: it does not depend on the Gestor, because it runs in the standalone updater, the API and the CLI. Load it with require_once.
-
Atomic creation (
fopenwithx): only one process creates the file. -
Lock content: owner, detail, execution, host, PID, start and expiry (
expires_at). -
Expired lock (a process that died without releasing): it is moved out of the way with an atomic
renameand taken over. The new owner receivesstaleto log it. -
Release and refresh: only the
tokenowner releases it;deploy_lock_refresh()extends the expiry for long runs.
Usage
-
deploy_lock_acquire($arquivo, $dono, $ttl)tries to take the lock. It returnsokand thetoken, orbusywith whoever holds it (holder). Creates the folder when missing. -
deploy_lock_release($arquivo, $token)releases it, only with the right token;deploy_lock_refresh($arquivo, $token, $ttl)extends the expiry. -
deploy_lock_read($arquivo)reads the current lock;deploy_lock_expired($trava)tells whether it expired (an unreadable lock counts as expired). -
deploy_lock_describe($trava)builds the refusal text: owner, detail, execution, host, PID, start and expiry.
Functions
Generated from gestor/bibliotecas/deploy-lock.php · 6 functions
deploy_lock_read
view source · line 24 ↗deploy_lock_read(string $arquivo): ?arrayLê a trava atual.
Parameters
$arquivostring
Returns
deploy_lock_expired
view source · line 31 ↗deploy_lock_expired(?array $trava, ?int $agora = null): boolA trava está vencida? (sem validade legível conta como vencida)
Parameters
$trava?array$agora?int
Returns
deploy_lock_acquire
view source · line 46 ↗deploy_lock_acquire(string $arquivo, array $dono, int $ttl = DEPLOY_LOCK_TTL): arrayTenta pegar a trava.
Parameters
$arquivostring- Caminho do arquivo de trava (a pasta é criada se faltar).
$donoarray- ['owner' => quem (ex.: 'update-system', 'api-project-update', 'pipeline'),
$ttlint- Validade em segundos.
Returns
deploy_lock_release
view source · line 83 ↗deploy_lock_release(string $arquivo, string $token): boolLibera a trava, só se o token for o dela.
Parameters
$arquivostring$tokenstring
Returns
deploy_lock_refresh
view source · line 90 ↗deploy_lock_refresh(string $arquivo, string $token, int $ttl = DEPLOY_LOCK_TTL): boolEstende a validade (execuções longas).
Parameters
$arquivostring$tokenstring$ttlint
Returns
deploy_lock_describe
view source · line 98 ↗deploy_lock_describe(?array $trava): stringTexto curto de quem está com a trava (mensagens de recusa).
Parameters
$trava?array
Returns