Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ generator = SlotGenerator(
timezone="Asia/Kolkata",
)

slots = generator.generate("2026-09-21", "2026-09-21")
slots = generator.generate("2026-10-05", "2026-10-05")

for slot in slots:
print(slot.start, "->", slot.end)
Expand Down Expand Up @@ -104,7 +104,7 @@ generator = SlotGenerator(
schedule = Schedule(
weekly={"monday": [("09:00", "17:00")]},
overrides={
"2026-09-21": [("13:00", "18:00")],
"2026-10-05": [("13:00", "18:00")],
"2026-09-28": [],
},
closed_dates=["2026-10-02"],
Expand Down Expand Up @@ -154,7 +154,7 @@ from datetime import datetime

slots = generator.upcoming(
7,
now=datetime.fromisoformat("2026-09-21T08:00:00+05:30"),
now=datetime.fromisoformat("2026-10-05T08:00:00+05:30"),
)
~~~

Expand Down Expand Up @@ -182,7 +182,7 @@ engine = AvailabilityEngine(
capacity=1,
)

available = engine.available_slots("2026-09-21")
available = engine.available_slots("2026-10-05")

if available:
booking = engine.reserve(available[0])
Expand Down Expand Up @@ -281,7 +281,7 @@ def available_slots(request, provider_id):
provider = Provider.objects.get(pk=provider_id)
engine = get_provider_engine(provider)

slots = engine.available_slots("2026-09-21")
slots = engine.available_slots("2026-10-05")

return JsonResponse({
"provider_id": provider.pk,
Expand Down
2 changes: 1 addition & 1 deletion SUPPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ For usage questions, open a GitHub issue with:
- a small reproducible example
- expected and actual behavior

For common patterns, start with the [documentation](https://failedengineers.github.io/Slotify/).
For common patterns, start with the [documentation](https://slotify-scheduling.ilovelabfile.in/).

## Bug reports

Expand Down
6 changes: 3 additions & 3 deletions docs/migration.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Migrating to v0.2.0
# Migrating to v0.4.0

Version 0.2.0 adds booking features while keeping the core slot-generation model.
Version 0.4.0 builds on the booking model with temporary holds, resource-pool allocation strategies, and clearer application-facing APIs.

## Existing slot generation

Expand Down Expand Up @@ -62,6 +62,6 @@ InMemoryBookingStore remains useful for tests and simple single-process services
python -c "import slotify; print(slotify.__version__)"
~~~

Expected: 0.2.0.
Expected: 0.4.0.

See the Changelog for release details.
2 changes: 1 addition & 1 deletion docs/recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ engine = AvailabilityEngine(
capacity=1,
)

available = engine.available_slots("2026-09-21")
available = engine.available_slots("2026-10-21")

if available:
booking = engine.reserve(available[0])
Expand Down
2 changes: 1 addition & 1 deletion docs/timezones.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ from datetime import datetime
slots = generator.upcoming(
7,
now=datetime.fromisoformat(
"2026-09-21T08:00:00-04:00"
"2026-10-05T08:00:00-04:00"
),
)
~~~
Expand Down
6 changes: 3 additions & 3 deletions marketing/LAUNCH_KIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ generator = SlotGenerator(
timezone="Asia/Kolkata",
)

slots = generator.generate("2026-09-21", "2026-09-21")
slots = generator.generate("2026-10-05", "2026-10-05")
~~~

It can also handle weekly schedules, date overrides, closures, breaks, DST policies, rolling availability, capacity, buffers, booking policies, reservations, and cancellation.

Docs: https://failedengineers.github.io/Slotify/
Docs: https://slotify-scheduling.ilovelabfile.in/
PyPI: https://pypi.org/project/slotify-scheduling/
GitHub: https://github.com/failedengineers/Slotify

Expand Down Expand Up @@ -83,7 +83,7 @@ pip install slotify-scheduling
~~~

Project: https://github.com/failedengineers/Slotify
Docs: https://failedengineers.github.io/Slotify/
Docs: https://slotify-scheduling.ilovelabfile.in/

I'm especially interested in feedback from people who have built appointment or resource-booking systems.

Expand Down
10 changes: 7 additions & 3 deletions src/slotify/availability.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,16 @@ def _validate_limits(
"The slot does not satisfy the minimum gap between bookings."
)

def _ordered_pool_resources(self, slot: Slot) -> tuple[str, ...]:
def _ordered_pool_resources(self, slot: Slot, *, advance: bool = False) -> tuple[str, ...]:
if not self.resource_pool:
return ()
resources = list(self.resource_pool)
if self.resource_strategy == "first_available":
return tuple(resources)
if self.resource_strategy == "round_robin":
offset = self._resource_cursor % len(resources)
self._resource_cursor = (self._resource_cursor + 1) % len(resources)
if advance:
self._resource_cursor = (self._resource_cursor + 1) % len(resources)
return tuple(resources[offset:] + resources[:offset])

def load(resource_id: str) -> int:
Expand Down Expand Up @@ -721,7 +722,10 @@ def reserve(

if self.resource_pool:
last_error: BookingConflictError | None = None
for resource_id in self._ordered_pool_resources(slot):
for resource_id in self._ordered_pool_resources(
slot,
advance=self.resource_strategy == "round_robin",
):
booking = self._candidate(
slot,
resource_id=resource_id,
Expand Down
22 changes: 22 additions & 0 deletions tests/test_v040_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,25 @@ def test_invalid_resource_strategy():
resource_pool=("a", "b"),
resource_strategy="random",
)


def test_round_robin_availability_checks_do_not_advance_selection():
engine = AvailabilityEngine(
make_generator(),
resource_pool=("a", "b"),
resource_strategy="round_robin",
)
slot = make_generator().generate_for_date("2026-10-05")[0]
now = datetime.fromisoformat("2026-10-04T08:00:00+05:30")

first = engine.check_availability(slot, now=now)
second = engine.check_availability(slot, now=now)

assert first.resource_id == "a"
assert second.resource_id == "a"

booking = engine.reserve(slot, now=now)
assert booking.resource_id == "a"

third = engine.check_availability(slot, now=now)
assert third.resource_id == "b"
Loading