reservations
reservations
#
Per-user time reservations — spread a crowd across candidate capture times.
Each user holds a distinct candidate time, stable while held and released once
it lapses or a capture lands within grace of it.
DEFAULT_GRACE = timedelta(minutes=30)
module-attribute
#
How long a reservation outlives its time when no grace is passed.
ReservationBook
#
Bases: ImpureState
The persistent book of reservations: each user's held instant.
held maps a user to the candidate time they currently hold. The struct
IS the format: changing its shape starts a fresh book (no migration).
Source code in capturegraph-lib/capturegraph/scheduling/organize/reservations.py
reserve(user_id, among, *, captured=None, now=None, grace=DEFAULT_GRACE)
#
The time this user holds, leasing a fresh distinct one if they hold none.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
str
|
The user asking for a time. |
required |
among
|
Iterable[datetime]
|
The current candidate times (regenerated per call is fine). |
required |
captured
|
datetime | None
|
The target's most recent capture (by any user), if known.
Every reservation at or before |
None
|
now
|
datetime | None
|
The reference time; defaults to |
None
|
grace
|
timedelta
|
How long a reservation outlives its time. A time more than
|
DEFAULT_GRACE
|
Returns:
| Type | Description |
|---|---|
datetime | None
|
The candidate this user holds (a member of |
datetime | None
|
when |
datetime | None
|
earliest is returned without recording a hold, so the answer in the |
datetime | None
|
oversubscribed case may drift between polls. |
Source code in capturegraph-lib/capturegraph/scheduling/organize/reservations.py
held_entries(held)
#
A book's held map as a plain {user_id: entry} dict (empty when unset).
Source code in capturegraph-lib/capturegraph/scheduling/organize/reservations.py
held_map(entries)
#
entries as the UserID-keyed map a book's state stores.