capturegraph.scheduling.organize.assignment_store
#
Assignment Store - Per-User Session Management#
Manages per-user notification assignments with automatic expiry and drift reconciliation for robust scheduling persistence.
Example
from capturegraph.scheduling.collaboration import AssignmentStore
store = AssignmentStore(
persistence=persistence,
expire_after=timedelta(hours=0.5),
last_capture=sessions[-1].date,
)
# Get existing assignment or assign next available session
next_session = store.assign_next(user_id, candidate_sessions)
AssignmentStore
#
Manages per-user session assignments with automatic expiry.
Stores assignments in persistence.assignments and handles:
- Automatic cleanup: Removes stale assignments on initialization
- Capture-aware expiry: Discards assignments after a new capture
- Drift reconciliation: Rounds assignments to nearest candidate sessions
Sessions must have a date attribute (datetime) for sorting and expiry checks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
persistence
|
Dict
|
Server persistence dict (must support attribute access). |
required |
expire_after
|
timedelta
|
Duration before an assignment expires. Defaults to 30 minutes. |
timedelta(hours=0.5)
|
last_capture
|
datetime | None
|
Timestamp of most recent capture session.
If provided, all assignments older than |
None
|
Example
from capturegraph.scheduling.collaboration import AssignmentStore
store = AssignmentStore(
persistence=persistence,
expire_after=timedelta(hours=3.0),
last_capture=target.Sunflower[-1].date,
)
# Check existing assignment
existing = store[user_id]
if existing is None:
# Assign to next available session
store[user_id] = candidate_sessions[0]
Source code in capturegraph-lib/capturegraph/scheduling/organize/assignment_store.py
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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
__getitem__(user_id)
#
Get the current assignment for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
str
|
The user's unique identifier. |
required |
Returns:
| Type | Description |
|---|---|
Dict[Any] | None
|
The assigned session Dict, or None if not assigned. |
Source code in capturegraph-lib/capturegraph/scheduling/organize/assignment_store.py
__setitem__(user_id, session)
#
Set an assignment for a user (no-op if already assigned).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
str
|
The user's unique identifier. |
required |
session
|
Dict[Any]
|
The session Dict to assign (must have a |
required |
Source code in capturegraph-lib/capturegraph/scheduling/organize/assignment_store.py
assign_next(user_id, sessions)
#
Assign the next available session to a user.
If the user already has an assignment, returns it. Otherwise, finds the first session not taken by another user and assigns it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
str
|
The user's unique identifier. |
required |
sessions
|
list[Dict[Any]]
|
Candidate sessions in chronological order. |
required |
Returns:
| Type | Description |
|---|---|
Dict[Any] | None
|
The assigned session, or |
Source code in capturegraph-lib/capturegraph/scheduling/organize/assignment_store.py
values(sessions=None)
#
Get all assigned sessions, optionally rounded to candidates.
When sessions is provided, performs drift reconciliation:
rounds each assignment to the nearest candidate session using
microsecond-precision distance checks on the date attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sessions
|
list[Dict[Any]] | None
|
Optional candidate sessions for rounding. |
None
|
Returns:
| Type | Description |
|---|---|
list[Dict[Any]]
|
List of assigned sessions (possibly rounded). |