31 lines
878 B
Python
31 lines
878 B
Python
#!/usr/bin/env python3
|
|
"""Run the independent calculation supervisor (never an API lifespan task)."""
|
|
import argparse
|
|
import asyncio
|
|
from pathlib import Path
|
|
import signal
|
|
import sys
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
from app.services.calculation_worker import CalculationWorker, WorkerSettings
|
|
|
|
|
|
async def main():
|
|
load_dotenv(Path(__file__).resolve().parents[1] / '.env', override=False)
|
|
task = asyncio.create_task(CalculationWorker(WorkerSettings.from_environment()).run())
|
|
loop = asyncio.get_running_loop()
|
|
for signum in (signal.SIGTERM, signal.SIGINT):
|
|
loop.add_signal_handler(signum, task.cancel)
|
|
try:
|
|
await task
|
|
except asyncio.CancelledError:
|
|
pass
|
|
|
|
|
|
if __name__ == '__main__':
|
|
argparse.ArgumentParser(description=__doc__).parse_args()
|
|
asyncio.run(main())
|