Dooratre commited on
Commit
b9ede24
·
verified ·
1 Parent(s): 4b00904

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -121,6 +121,15 @@ def random_sleep_tick():
121
  def now_utc():
122
  return datetime.datetime.now(datetime.timezone.utc)
123
 
 
 
 
 
 
 
 
 
 
124
  def format_zone_times(dt_utc: datetime.datetime) -> Dict[str, Any]:
125
  def last_sunday(year, month):
126
  d = datetime.datetime(year, month, 31, tzinfo=datetime.timezone.utc)
@@ -582,10 +591,10 @@ def track_signal():
582
  def _activator():
583
  try:
584
  # Read scenario once and cache SL/TP locally to avoid race
585
- scenario_blob = fetch_current_scenario_struct()
586
  if not scenario_blob or "scenario" not in scenario_blob:
587
- logger.error("[ACTIVATOR] Missing scenario data before waiting.")
588
- send_message_to_users("ERROR: Missing scenario structure before activation. Please set scenario and retry.")
589
  return
590
 
591
  scen = scenario_blob["scenario"]
 
121
  def now_utc():
122
  return datetime.datetime.now(datetime.timezone.utc)
123
 
124
+ def fetch_scenario_with_retries(max_attempts=5, delay_sec=3):
125
+ for attempt in range(1, max_attempts + 1):
126
+ scen = fetch_current_scenario_struct()
127
+ if scen and "scenario" in scen:
128
+ return scen
129
+ if attempt < max_attempts:
130
+ time.sleep(delay_sec)
131
+ return None
132
+
133
  def format_zone_times(dt_utc: datetime.datetime) -> Dict[str, Any]:
134
  def last_sunday(year, month):
135
  d = datetime.datetime(year, month, 31, tzinfo=datetime.timezone.utc)
 
591
  def _activator():
592
  try:
593
  # Read scenario once and cache SL/TP locally to avoid race
594
+ scenario_blob = fetch_scenario_with_retries(max_attempts=5, delay_sec=3)
595
  if not scenario_blob or "scenario" not in scenario_blob:
596
+ logger.error("[ACTIVATOR] Missing scenario data before waiting (after retries).")
597
+ send_message_to_users("ERROR: Missing scenario structure before activation (after retries). Please set scenario and retry.")
598
  return
599
 
600
  scen = scenario_blob["scenario"]