Alialdlfy1 commited on
Commit
59fcfb2
·
verified ·
1 Parent(s): 733e117

Update bot_core.py

Browse files
Files changed (1) hide show
  1. 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
- if idle_poll >= 3600 and now - _last_watchdog_alert >= 3600:
520
- _last_watchdog_alert = now
521
- logger.warning(f"⚠️ Watchdog: لا يوجد فحص ناجح منذ {idle_poll} ثانية")
522
- await notify_admins(f"⚠️ تنبيه مراقبة: لا يوجد فحص ناجح منذ {idle_poll // 60} دقيقة. إذا لم يرجع النشر، افتح الاستضافة أو سوِ Restart.")
523
- await reconnect_user_client_if_needed("watchdog idle poll")
 
 
 
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)