Implement lab 5 durable image processing worker
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
"""Explicit local Compose failure hooks. Never deletes volumes."""
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
os.chdir(ROOT)
|
||||
mode = sys.argv[1]
|
||||
if mode == 'restart':
|
||||
services = subprocess.check_output(['docker', 'compose', 'ps', '--services', '--status', 'running'], text=True).split()
|
||||
subprocess.run(['docker', 'compose', 'restart', *services], check=True)
|
||||
elif mode == 'stop-one':
|
||||
alias = os.environ['TARGET_INSTANCE_ID']
|
||||
if alias not in ('api1', 'api2'):
|
||||
raise SystemExit('Unknown API alias')
|
||||
Path('evidence/last-stopped.json').write_text(json.dumps({'service': alias}), encoding='utf-8')
|
||||
subprocess.run(['docker', 'compose', 'stop', '-t', '2', alias], check=True)
|
||||
else:
|
||||
raise SystemExit('Unknown action')
|
||||
Reference in New Issue
Block a user