-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
62 lines (48 loc) · 1.63 KB
/
Copy pathrun.py
File metadata and controls
62 lines (48 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""MOI Agent — Point d'entrée unique. Lance tous les services en parallèle."""
import asyncio
import signal
import sys
from core.config import settings
from core.log import log
async def main():
log.info("MOI Agent starting...")
# Import services
from dashboard.app import start_dashboard
from tgbot.bot import start_telegram
from agent.loop import start_agent_loop
from agent.cron import run_cron_loop
# Graceful shutdown
stop_event = asyncio.Event()
def _shutdown(*_):
log.info("Shutting down...")
stop_event.set()
if sys.platform != "win32":
for sig in (signal.SIGINT, signal.SIGTERM):
asyncio.get_event_loop().add_signal_handler(sig, _shutdown)
tasks = [
asyncio.create_task(start_dashboard(stop_event)),
asyncio.create_task(start_agent_loop(stop_event)),
asyncio.create_task(run_cron_loop(stop_event)),
]
# Telegram is optional
if settings.telegram_bot_token:
tasks.append(asyncio.create_task(start_telegram(stop_event)))
log.info("Telegram bot enabled")
else:
log.warning("TELEGRAM_BOT_TOKEN not set — bot disabled")
log.info(
f"Services running: dashboard(:8000), agent-loop, cron"
f"{', telegram' if settings.telegram_bot_token else ''}"
)
try:
await asyncio.gather(*tasks)
except (KeyboardInterrupt, asyncio.CancelledError):
_shutdown()
for t in tasks:
t.cancel()
await asyncio.gather(*tasks, return_exceptions=True)
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
pass