@@ -115,24 +115,19 @@ def is_datetime_future(dt, current_threshold=None):
115115 return dt > current_threshold
116116
117117
118- def ensure_future_datetime (schedule_obj , current_threshold = None , max_retries = 5 ):
118+ def ensure_future_datetime (schedule_obj , current_threshold = None ):
119119 """
120120 Ensure a schedule's next() call returns a datetime strictly in the future.
121121
122- This is a defensive utility for cron/schedule libraries that should always return
123- future times but may have edge cases. Validates and retries if needed.
122+ Keeps calling .next() until a future time is returned — never raises.
124123
125124 Args:
126125 schedule_obj: A schedule object with a .next() method (e.g., from croniter/APScheduler)
127126 current_threshold: datetime to compare against. If None, uses timeNowTZ(as_string=False)
128- max_retries: Maximum times to call .next() if result is not in future (default: 5)
129127
130128 Returns:
131129 datetime.datetime: A guaranteed future datetime from schedule_obj.next()
132130
133- Raises:
134- RuntimeError: If max_retries exceeded without getting a future time
135-
136131 Examples:
137132 newSchedule = Cron(run_sch).schedule(start_date=timeNowUTC(as_string=False))
138133 next_time = ensure_future_datetime(newSchedule)
@@ -141,17 +136,9 @@ def ensure_future_datetime(schedule_obj, current_threshold=None, max_retries=5):
141136 current_threshold = timeNowTZ (as_string = False )
142137
143138 next_time = schedule_obj .next ()
144- retries = 0
145139
146- while next_time <= current_threshold and retries < max_retries :
140+ while next_time <= current_threshold :
147141 next_time = schedule_obj .next ()
148- retries += 1
149-
150- if next_time <= current_threshold :
151- raise RuntimeError (
152- f"[ensure_future_datetime] Failed to get future time after { max_retries } retries. "
153- f"Last attempt: { next_time } , Current time: { current_threshold } "
154- )
155142
156143 return next_time
157144
0 commit comments