store
File-backed persistence store for pending change queue items.
PendingQueueStore
File-backed storage for pending queue records.
Source code in src/horde_model_reference/pending_queue/store.py
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 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 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | |
__init__
Create a store rooted at the provided filesystem path.
Source code in src/horde_model_reference/pending_queue/store.py
enqueue_change
Persist a new pending change and allocate an id if needed.
Source code in src/horde_model_reference/pending_queue/store.py
get_change
Return a copy of the requested change, if available.
Source code in src/horde_model_reference/pending_queue/store.py
list_changes
list_changes(
*,
queue_filter: PendingQueueFilter | None = None,
offset: int = 0,
limit: int | None = None,
) -> tuple[list[PendingChangeRecord], int]
Return filtered records and total count before pagination.
Source code in src/horde_model_reference/pending_queue/store.py
purge_changes
Delete queue entries matching the provided filter and return removed copies.
Source code in src/horde_model_reference/pending_queue/store.py
save_many
Persist multiple records atomically.
Source code in src/horde_model_reference/pending_queue/store.py
get_current_pending_batch_id
Return the batch ID of the current open batch (APPROVED but not yet applied).
Batch ID Semantics: - All approved-but-unapplied changes share the same batch ID. - A new batch ID is only created when: 1. No unapplied batch exists (first approval after all batches are applied). 2. A batch was partially applied (remaining changes get a new batch ID). - This ensures approvals are grouped together until application.
Returns:
-
int | None–The batch ID of existing APPROVED changes, or None if no open batch exists.
Source code in src/horde_model_reference/pending_queue/store.py
get_or_create_pending_batch_id
Get the current pending batch ID, or create a new one if none exists.
This method ensures all approved-but-unapplied changes share the same batch ID. A new batch ID is only allocated when no APPROVED changes exist.
Returns:
-
int–The batch ID to use for new approvals.
Source code in src/horde_model_reference/pending_queue/store.py
_get_current_pending_batch_id_locked
Find existing APPROVED batch ID without acquiring lock.
Source code in src/horde_model_reference/pending_queue/store.py
has_approved_changes_in_batch
Check if any APPROVED changes remain in the specified batch.
Used after applying changes to determine if the batch was partially applied.
Parameters:
-
batch_id(int) –The batch ID to check.
Returns:
-
bool–True if APPROVED changes exist in the batch, False otherwise.
Source code in src/horde_model_reference/pending_queue/store.py
get_approved_changes_in_batch
Return all APPROVED changes in the specified batch.
Parameters:
-
batch_id(int) –The batch ID to filter by.
Returns:
-
list[PendingChangeRecord]–List of APPROVED change records in the batch.
Source code in src/horde_model_reference/pending_queue/store.py
next_batch_id
Allocate the next batch id unconditionally.
Note: For normal approval operations, use get_or_create_pending_batch_id() to reuse existing unapplied batch IDs. This method is used when a new batch ID must be created (e.g., after partial batch application).
Source code in src/horde_model_reference/pending_queue/store.py
_matches_filter
Source code in src/horde_model_reference/pending_queue/store.py
_load_state
Load the index.json state file. Returns True on success, False on missing/corrupt.
Source code in src/horde_model_reference/pending_queue/store.py
_load_changes
Source code in src/horde_model_reference/pending_queue/store.py
_recover_ids_from_changes
Recover last_change_id and last_batch_id from loaded change records after state corruption.
Source code in src/horde_model_reference/pending_queue/store.py
_persist_locked
Source code in src/horde_model_reference/pending_queue/store.py
_persist_state_locked
_next_change_id_locked
reserve_for_apply
Transition an APPROVED change to APPLYING and set the reservation.
The reservation is recorded on the change via applied_job_id to prevent
concurrent apply attempts from issuing duplicate backend mutations. The
status moves to APPLYING so that a crash mid-apply is detectable on
restart.
Source code in src/horde_model_reference/pending_queue/store.py
clear_reservation_if_matches
Release a reservation if it still matches, reverting APPLYING → APPROVED.
Source code in src/horde_model_reference/pending_queue/store.py
get_applying_records
Return all records currently in APPLYING state.
Used on startup to detect changes that were mid-apply when the process crashed. Callers should log warnings and decide whether to retry or revert each one.
Source code in src/horde_model_reference/pending_queue/store.py
revert_applying_to_approved
Revert a stuck APPLYING record back to APPROVED.
Parameters:
-
change_id(int) –The change to revert.
Returns:
-
PendingChangeRecord–The updated record.
Raises:
-
ValueError–If the record is missing or not in APPLYING state.
Source code in src/horde_model_reference/pending_queue/store.py
assert_pending
Validate that a record is still pending before mutation.