@@ -309,18 +309,54 @@ def compute_runahead(self, force=False) -> bool:
309309 With force=True we recompute the limit even if the base point has not
310310 changed (needed if max_future_offset changed, or on reload).
311311 """
312+
313+ limit = self .config .runahead_limit # e.g. P2 or P2D
314+ count_cycles = False
315+ with suppress (TypeError ):
316+ # Count cycles (integer cycling, and optional for datetime too).
317+ ilimit = int (limit ) # type: ignore
318+ count_cycles = True
319+
320+ base_point : 'PointBase'
312321 points : List ['PointBase' ] = []
313- sequence_points : Set [ 'PointBase' ]
322+
314323 if not self .main_pool :
315- # Start at first point in each sequence, after the initial point.
316- points = [
317- point
318- for point in {
319- seq .get_first_point (self .config .start_point )
320- for seq in self .config .sequences
321- }
322- if point is not None
323- ]
324+ # No tasks yet, just consider sequence points.
325+ if count_cycles :
326+ # Get the first ilimit points in each sequence.
327+ # (After workflow start point - sequence may begin earlier).
328+ points = [
329+ point
330+ for plist in [
331+ seq .get_first_n_points (
332+ ilimit , self .config .start_point )
333+ for seq in self .config .sequences
334+ ]
335+ for point in plist
336+ ]
337+ # Drop points beyond the limit.
338+ points = sorted (points )[:ilimit + 1 ]
339+ base_point = min (points )
340+
341+ else :
342+ # Start at first point in each sequence.
343+ # (After workflow start point - sequence may begin earlier).
344+ points = [
345+ point
346+ for point in {
347+ seq .get_first_point (self .config .start_point )
348+ for seq in self .config .sequences
349+ }
350+ if point is not None
351+ ]
352+ base_point = min (points )
353+ # Drop points beyond the limit.
354+ points = [
355+ point
356+ for point in points
357+ if point <= base_point + limit
358+ ]
359+
324360 else :
325361 # Find the earliest point with unfinished tasks.
326362 for point , itasks in sorted (self .get_tasks_by_point ().items ()):
@@ -344,9 +380,10 @@ def compute_runahead(self, force=False) -> bool:
344380 )
345381 ):
346382 points .append (point )
347- if not points :
348- return False
349- base_point = min (points )
383+
384+ if not points :
385+ return False
386+ base_point = min (points )
350387
351388 if self ._prev_runahead_base_point is None :
352389 self ._prev_runahead_base_point = base_point
@@ -363,15 +400,8 @@ def compute_runahead(self, force=False) -> bool:
363400 # change or the runahead limit is already at stop point.
364401 return False
365402
366- try :
367- limit = int (self .config .runahead_limit ) # type: ignore
368- except TypeError :
369- count_cycles = False
370- limit = self .config .runahead_limit
371- else :
372- count_cycles = True
373-
374- # Get all cycle points possible after the runahead base point.
403+ # Get all cycle points possible after the base point.
404+ sequence_points : Set ['PointBase' ]
375405 if (
376406 not force
377407 and self ._prev_runahead_sequence_points
@@ -388,7 +418,7 @@ def compute_runahead(self, force=False) -> bool:
388418 while seq_point is not None :
389419 if count_cycles :
390420 # P0 allows only the base cycle point to run.
391- if count > 1 + limit :
421+ if count > 1 + ilimit :
392422 break
393423 else :
394424 # PT0H allows only the base cycle point to run.
@@ -404,7 +434,7 @@ def compute_runahead(self, force=False) -> bool:
404434
405435 if count_cycles :
406436 # Some sequences may have different intervals.
407- limit_point = sorted (points )[:(limit + 1 )][- 1 ]
437+ limit_point = sorted (points )[:(ilimit + 1 )][- 1 ]
408438 else :
409439 # We already stopped at the runahead limit.
410440 limit_point = sorted (points )[- 1 ]
0 commit comments