fix(scheduler): fill schedule gaps instead of always appending to end
Previously the scheduler started searching from the last scheduled post date, skipping all free slots in between (e.g. a free slot on Apr 20 would be ignored if the last post was on May 18). Now starts scanning from tomorrow, finding the first available slot regardless of whether earlier dates have gaps — fills the calendar naturally. Also extended lookahead from 30 to 60 days. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8fa46312e8
commit
94bd93a18a
1 changed files with 7 additions and 6 deletions
|
|
@ -146,17 +146,18 @@ def _format_slot(d: date, hour: int) -> str:
|
|||
|
||||
|
||||
def _find_next_free_slot(
|
||||
wp_occupied: set[tuple[str, int]], lookahead_days: int = 30
|
||||
wp_occupied: set[tuple[str, int]], lookahead_days: int = 60
|
||||
) -> tuple[date, int] | None:
|
||||
"""Find the next free (date, hour) slot, anchored after the last scheduled article."""
|
||||
"""Find the next free (date, hour) slot.
|
||||
|
||||
Starts from tomorrow and scans forward, filling any gaps in the schedule
|
||||
rather than always appending after the last existing post.
|
||||
"""
|
||||
today = _today_cet()
|
||||
tomorrow = today + timedelta(days=1)
|
||||
|
||||
last_date = _get_last_future_scheduled_date(wp_occupied)
|
||||
start_date = last_date if (last_date and last_date >= tomorrow) else tomorrow
|
||||
|
||||
for offset in range(0, lookahead_days + 1):
|
||||
candidate = start_date + timedelta(days=offset)
|
||||
candidate = tomorrow + timedelta(days=offset)
|
||||
hour = _next_free_hour(candidate, wp_occupied)
|
||||
if hour is not None:
|
||||
return candidate, hour
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue