-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatchdog_runner.py
More file actions
73 lines (56 loc) · 1.67 KB
/
Copy pathwatchdog_runner.py
File metadata and controls
73 lines (56 loc) · 1.67 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
63
64
65
66
67
68
69
70
71
72
73
"""
Watchdog Runner - Standalone watchdog process for PM2.
This script runs the watchdog as a separate process that monitors
the main FTE processes and restarts them if they crash.
Run with: python watchdog_runner.py
Or with PM2: pm2 start ecosystem.config.js (includes fte-watchdog)
"""
import asyncio
import logging
import sys
from pathlib import Path
# Ensure local imports work
sys.path.insert(0, str(Path(__file__).parent))
from watchdog import Watchdog, write_heartbeat
# Configure logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
handlers=[
logging.StreamHandler(sys.stdout),
],
)
logger = logging.getLogger(__name__)
async def main():
"""Run the watchdog process."""
vault_path = Path("AI_Employee_Vault")
logs_path = vault_path / "Logs"
# Write initial heartbeat
write_heartbeat("watchdog")
# Create and run watchdog
watchdog = Watchdog(
vault_path=vault_path,
logs_path=logs_path,
check_interval=60.0, # 60 seconds as specified
auto_restart=True,
)
await watchdog.initialize()
# Heartbeat loop
async def heartbeat_loop():
while True:
write_heartbeat("watchdog")
await asyncio.sleep(30)
# Run watchdog and heartbeat together
heartbeat_task = asyncio.create_task(heartbeat_loop())
try:
await watchdog.run()
except KeyboardInterrupt:
logger.info("Watchdog interrupted")
finally:
heartbeat_task.cancel()
logger.info("Watchdog stopped")
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
pass