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-recipes/capturegraph_recipes/scheduling/organize/reservations.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
reserve(user_id, among, *, captured=None, now=None, grace=DEFAULT_GRACE, otherwise=None)
#
The time this user holds, leasing a fresh distinct one if they hold none.
@cgserver.intercept(Journal, lambda s: s._metadata._next_notification)
def notification(profile: cgserver.RequestProfile, target: Journal) -> datetime:
return cgr.scheduling.ReservationBook.open("journal").reserve(
profile.user_id,
cgr.scheduling.forecast.times_of_day(hours=[9, 13, 17]),
captured=target.sessions,
otherwise=timedelta(hours=1),
)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
str
|
The user asking for a time. |
required |
among
|
Iterable[datetime | Time]
|
The current candidate times (regenerated per call is fine). |
required |
captured
|
datetime | Map | None
|
The target's most recent capture (by any user), or the
sessions keyed by capture time, whose latest key it is. 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
|
otherwise
|
timedelta | None
|
When given, the answer when |
None
|
Returns:
| Type | Description |
|---|---|
datetime | None
|
The candidate this user holds (a member of |
datetime | None
|
|
datetime | None
|
|
datetime | None
|
returned without recording a hold, so the answer in the |
datetime | None
|
oversubscribed case may drift between polls. |
Source code in capturegraph-recipes/capturegraph_recipes/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-recipes/capturegraph_recipes/scheduling/organize/reservations.py
held_map(entries)
#
entries as the UserID-keyed map a book's state stores.