Spaces:
Running
Running
Update bot_core.py
Browse files- bot_core.py +9 -6
bot_core.py
CHANGED
|
@@ -503,7 +503,7 @@ async def _verify_channel_before_publish(target):
|
|
| 503 |
|
| 504 |
|
| 505 |
async def heartbeat_watchdog_loop():
|
| 506 |
-
"""نبض مراقبة: يطبع حالة دورية وي
|
| 507 |
global _last_watchdog_alert, _last_heartbeat_log
|
| 508 |
await asyncio.sleep(60)
|
| 509 |
while True:
|
|
@@ -516,11 +516,14 @@ async def heartbeat_watchdog_loop():
|
|
| 516 |
_last_heartbeat_log = now
|
| 517 |
logger.info(f"💓 Heartbeat OK | آخر فحص قبل {idle_poll}s | آخر نشر قبل {idle_publish}s")
|
| 518 |
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
logger.
|
| 522 |
-
|
| 523 |
-
|
|
|
|
|
|
|
|
|
|
| 524 |
except Exception as e:
|
| 525 |
logger.warning(f"⚠️ خطأ في Heartbeat/Watchdog: {e}")
|
| 526 |
await asyncio.sleep(60)
|
|
|
|
| 503 |
|
| 504 |
|
| 505 |
async def heartbeat_watchdog_loop():
|
| 506 |
+
"""نبض مراقبة: يطبع حالة دورية ويعيد تشغيل البوت تلقائياً إذا علق الفحص."""
|
| 507 |
global _last_watchdog_alert, _last_heartbeat_log
|
| 508 |
await asyncio.sleep(60)
|
| 509 |
while True:
|
|
|
|
| 516 |
_last_heartbeat_log = now
|
| 517 |
logger.info(f"💓 Heartbeat OK | آخر فحص قبل {idle_poll}s | آخر نشر قبل {idle_publish}s")
|
| 518 |
|
| 519 |
+
# إذا توقف الفحص لمدة 10 دقائق (600 ثانية)، نجبر العملية على الإغلاق ليعيد start.sh تشغيلها فوراً
|
| 520 |
+
if idle_poll >= 600:
|
| 521 |
+
logger.error(f"🚨 Watchdog: توقف الفحص منذ {idle_poll} ثانية! جاري إعادة تشغيل البوت تلقائياً...")
|
| 522 |
+
try:
|
| 523 |
+
await notify_admins(f"🔄 تنبيه تلقائي: توقف فحص المصادر لمدة {idle_poll // 60} دقائق، وتمت إعادة تشغيل البوت تلقائياً.")
|
| 524 |
+
except Exception:
|
| 525 |
+
pass
|
| 526 |
+
os._exit(1)
|
| 527 |
except Exception as e:
|
| 528 |
logger.warning(f"⚠️ خطأ في Heartbeat/Watchdog: {e}")
|
| 529 |
await asyncio.sleep(60)
|