TTOPM commited on
Commit
43fcf37
Β·
verified Β·
1 Parent(s): 075d78a

Upload symbiont_scheduler.py

Browse files
src/protocol/daemon/symbiont_scheduler.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import time
2
+ from datetime import datetime
3
+
4
+ from src.protocol.symbiont.symbiont_introspect import SymbiontIntrospect
5
+ from src.protocol.permanent_memory import PermanentMemory
6
+ from src.protocol.decentralized_comm.ipfs_client import IPFSClient
7
+ from src.protocol.security.alert_webhook import WebhookAlerter
8
+
9
+ # === Configuration ===
10
+ INTROSPECTION_INTERVAL = 3600 # Run every hour (in seconds)
11
+ WEBHOOK_URL = "https://discord.com/api/webhooks/xxx/yyy" # Replace with your actual webhook
12
+
13
+ # === Initialize Components ===
14
+ memory = PermanentMemory(log_dir="./symbiont_logs")
15
+ ipfs = IPFSClient()
16
+ introspect = SymbiontIntrospect(memory=memory, ipfs_client=ipfs)
17
+ alerter = WebhookAlerter(WEBHOOK_URL)
18
+
19
+
20
+ def main():
21
+ print("πŸ” Symbiont Introspection Scheduler Started")
22
+ print(f"⏱ Interval set to every {INTROSPECTION_INTERVAL / 60:.0f} minutes\n")
23
+
24
+ while True:
25
+ print(f"⏳ Starting introspection cycle: {datetime.now().isoformat()}")
26
+
27
+ try:
28
+ introspect.run_introspection()
29
+ print("βœ… Introspection complete.\n")
30
+
31
+ except Exception as e:
32
+ error_msg = f"❌ Introspection failed at {datetime.now().isoformat()}:\n{str(e)}"
33
+ memory.log_event("IntrospectionError", error_msg)
34
+ alerter.send_alert("Symbiont Introspection Failure", error_msg)
35
+ print(error_msg + "\n")
36
+
37
+ time.sleep(INTROSPECTION_INTERVAL)
38
+
39
+
40
+ if __name__ == "__main__":
41
+ try:
42
+ main()
43
+ except KeyboardInterrupt:
44
+ print("πŸ›‘ Scheduler interrupted by user. Exiting gracefully.")
45
+ except Exception as critical_failure:
46
+ failure_msg = f"πŸ”₯ Critical failure in scheduler loop: {str(critical_failure)}"
47
+ memory.log_event("SchedulerCriticalError", failure_msg)
48
+ alerter.send_alert("Critical Scheduler Crash", failure_msg)
49
+ raise