Files
mtusi2026lab7/worker/pipeline/config.py

32 lines
1.2 KiB
Python

import os
import json
import time
from dataclasses import dataclass
from pathlib import Path
def credentials():
operator_file = os.getenv("OPERATOR_CREDENTIALS_FILE")
if operator_file:
return json.loads(Path(operator_file).read_text())
if time.time() > float(Path("/runtime/lease").read_text()):
raise RuntimeError("service_identity_expired")
return json.loads(Path("/runtime/secrets.json").read_text())
@dataclass(frozen=True)
class Settings:
db_host: str = os.getenv("DB_HOST", "db")
broker_host: str = os.getenv("BROKER_HOST", "broker")
bucket: str = os.getenv("S3_BUCKET", "messenger-attachments")
endpoint: str = os.getenv("S3_ENDPOINT", "https://minio:9000")
max_attempts: int = int(os.getenv("JOB_MAX_ATTEMPTS", "5"))
timeout: int = int(os.getenv("JOB_TIMEOUT_SECONDS", "60"))
retention: int = int(os.getenv("STAGING_RETENTION_SECONDS", "86400"))
lease: int = int(os.getenv("JOB_LEASE_SECONDS", "75"))
faults: bool = os.getenv("FAULT_INJECTION_ENABLED", "false").lower() == "true"
max_bytes: int = 10485760
max_pixels: int = 40000000
stream: str = "attachment-jobs"
group: str = "image-workers"