Files
InterferenceETL/etl_app/worker.py
T

59 lines
2.2 KiB
Python

from __future__ import annotations
import argparse
import sys
import traceback
from pathlib import Path
import main
from .config import SettingsStore
from .connectors import build_client, build_storage, build_store, close_quietly
def run(settings_path: Path, output_dir: Path, dry_run: bool) -> int:
settings = SettingsStore(settings_path).get()
print(f"storage_mode={settings.storage_mode}")
print(f"database_mode={'none' if dry_run else settings.database_mode}")
client = build_client(settings)
storage = build_storage(settings, client)
try:
source = main.StorageSource(storage, settings.source_root, settings.cell_data_directories)
store = None if dry_run else build_store(settings, client)
history = None
if store is not None and settings.history_enabled:
history = main.StorageHistoryStore(storage, settings.history_root)
if not dry_run and settings.history_keep_days > 0:
try:
removed = main.StorageHistoryStore(storage, settings.history_root).prune(settings.history_keep_days)
except main.ProcessingError as exc:
print(f"history_prune_error={exc}")
else:
for path in removed:
print(f"history_removed={path}")
main.process(source, output_dir, settings.lookback_days, store=store, history=history)
finally:
close_quietly(storage)
return 0
def entry(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(description="Run one InterferenceETL pass with the saved app settings")
parser.add_argument("--settings", type=Path, required=True)
parser.add_argument("--output", type=Path, required=True)
parser.add_argument("--dry-run", action="store_true")
args = parser.parse_args(argv)
try:
return run(args.settings, args.output, args.dry_run)
except main.ProcessingError as exc:
print(f"error={exc}", file=sys.stderr, flush=True)
return 1
except Exception as exc:
traceback.print_exc()
print(f"error={type(exc).__name__}: {exc}", file=sys.stderr, flush=True)
return 1
if __name__ == "__main__":
raise SystemExit(entry())