Files
FitOS/ops/deploy/agent/deploy_queue.py

31 lines
1.1 KiB
Python

"""Czysta logika stanow kolejki deployow agenta (zero IO — pelna do testow).
Wejscie: head_sha (origin/main), last_success_sha (SHA z RELEASE stosu),
last_attempt_sha + fail_count (ostatnia proba agenta), max_retries.
Wyjscie: jedna z akcji:
in_sync — staging stoi juz na tym SHA, nic do roboty
deploy — wystaw ten SHA (nowy commit LUB auto-ponowienie po bladzie)
parked — ten SHA obil juz max_retries prob; czekamy na nowy commit,
zeby nie mielc te same awarie w kolko co catch-up
Sam catch-up (timer + webhook) zyciem tej logiki zajmuje sie listener.py.
"""
from __future__ import annotations
ACTION_IN_SYNC = "in_sync"
ACTION_DEPLOY = "deploy"
ACTION_PARKED = "parked"
def next_action(head_sha: str, last_success_sha: str, last_attempt_sha: str,
fail_count: int, max_retries: int) -> str:
if not head_sha:
raise ValueError("head_sha nie moze byc pusty")
if head_sha == last_success_sha:
return ACTION_IN_SYNC
if head_sha == last_attempt_sha and fail_count >= max_retries:
return ACTION_PARKED
return ACTION_DEPLOY