61 lines
1.5 KiB
Python
61 lines
1.5 KiB
Python
"""Keep outbound Celery work paused during a verified cold-data migration.
|
|
|
|
The operator creates the hold file in the candidate data clone before startup
|
|
and removes it only after committing the verified deployment. Normal startups
|
|
without a hold file behave unchanged. This does not pause an existing worker.
|
|
"""
|
|
|
|
import os
|
|
import stat
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
HOLD_FILE = Path("/app/local/.migration-worker-hold")
|
|
COMMANDS = {
|
|
"worker": [
|
|
"/app/.venv/bin/celery",
|
|
"-A",
|
|
"config",
|
|
"worker",
|
|
"-l",
|
|
"INFO",
|
|
"-Q",
|
|
"high,default,low",
|
|
"--concurrency=2",
|
|
],
|
|
"scheduler": [
|
|
"/app/.venv/bin/celery",
|
|
"-A",
|
|
"config",
|
|
"beat",
|
|
"-l",
|
|
"INFO",
|
|
"--schedule",
|
|
"/tmp/celerybeat-schedule", # noqa: S108 - existing supervised container-local schedule path
|
|
],
|
|
}
|
|
|
|
|
|
def hold_active(path=HOLD_FILE):
|
|
try:
|
|
mode = path.lstat().st_mode
|
|
except FileNotFoundError:
|
|
return False
|
|
if not stat.S_ISREG(mode):
|
|
raise RuntimeError("Migration hold must be a regular file")
|
|
return True
|
|
|
|
|
|
def start(role, *, check=hold_active, sleep=time.sleep, execute=os.execv):
|
|
if role not in COMMANDS:
|
|
raise ValueError("Unsupported supervised process")
|
|
while check():
|
|
sleep(1)
|
|
command = COMMANDS[role]
|
|
execute(command[0], command)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
start(sys.argv[1] if len(sys.argv) == 2 else "")
|