Fix live runner next-cycle timestamp parsing

This commit is contained in:
Thigazhezhilan J 2026-04-07 10:09:16 +05:30
parent 8d1eaafebb
commit 99e48144aa

View File

@ -156,6 +156,19 @@ def _last_execution_anchor(state: dict, mode: str) -> str | None:
return state.get("last_run") or state.get("last_sip_ts")
def _parse_market_timestamp(value: str | None) -> datetime | None:
if not value:
return None
try:
parsed = datetime.fromisoformat(value)
except ValueError:
return None
market_tz = market_now().tzinfo
if parsed.tzinfo is None:
return parsed.replace(tzinfo=market_tz)
return parsed.astimezone(market_tz)
def _pause_for_auth_expiry(
user_id: str,
run_id: str,
@ -330,9 +343,9 @@ def _engine_loop(config, stop_event: threading.Event):
)
if last_run and not is_first_run:
next_run = datetime.fromisoformat(last_run) + delta
next_run = align_to_market_open(next_run)
if now < next_run:
parsed_last_run = _parse_market_timestamp(last_run)
next_run = align_to_market_open(parsed_last_run + delta) if parsed_last_run else None
if next_run is not None and now < next_run:
wait_seconds = 5 if unit == "minutes" else 60
log_event(
event="SIP_WAITING",