fix: scheduler timezone-aware datetime subtraction in is_source_due

This commit is contained in:
Celes Renata
2026-04-20 00:47:26 +00:00
parent f3aac0ac3d
commit d64ce82649
+16 -3
View File
@@ -125,8 +125,16 @@ def is_source_due(
if last_status == "failed": if last_status == "failed":
if retry_count >= MAX_RETRY_COUNT: if retry_count >= MAX_RETRY_COUNT:
return False return False
if next_retry_at and now < next_retry_at.replace(tzinfo=None): if next_retry_at:
return False # Normalize tz-awareness to match 'now'
if now.tzinfo is not None and next_retry_at.tzinfo is None:
nra = next_retry_at.replace(tzinfo=timezone.utc)
elif now.tzinfo is None and next_retry_at.tzinfo is not None:
nra = next_retry_at.replace(tzinfo=None)
else:
nra = next_retry_at
if now < nra:
return False
# Backoff elapsed or no next_retry_at set — allow retry # Backoff elapsed or no next_retry_at set — allow retry
return True return True
@@ -139,7 +147,12 @@ def is_source_due(
return True return True
cadence = get_cadence_for_source(source_type, source_config) cadence = get_cadence_for_source(source_type, source_config)
elapsed = (now - last_completed_at.replace(tzinfo=None)).total_seconds() # Ensure both datetimes have matching tz-awareness for subtraction
if now.tzinfo is not None and last_completed_at.tzinfo is None:
last_completed_at = last_completed_at.replace(tzinfo=timezone.utc)
elif now.tzinfo is None and last_completed_at.tzinfo is not None:
last_completed_at = last_completed_at.replace(tzinfo=None)
elapsed = (now - last_completed_at).total_seconds()
return elapsed >= cadence return elapsed >= cadence