teff.checkpoint.base¶
teff.checkpoint.base
¶
Checkpointing primitives for durable graph execution.
Classes:
| Name | Description |
|---|---|
Checkpoint |
A snapshot of execution that can be resumed from. |
Checkpointer |
Interface for persisting execution checkpoints. |
Functions:
| Name | Description |
|---|---|
checkpoint_from_dict |
Reconstruct a checkpoint from a dict produced by :func: |
checkpoint_to_dict |
Convert a checkpoint to a JSON-serializable dict. |
Checkpoint
dataclass
¶
A snapshot of execution that can be resumed from.
Attributes:
| Name | Type | Description |
|---|---|---|
state |
dict
|
Workflow state data (JSON-serializable dict). |
next_node_id |
str | None
|
ID of the node to execute on resume.
|
iteration |
int
|
Number of completed node executions so far. |
Source code in teff/checkpoint/base.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
Checkpointer
¶
Bases: Protocol
Interface for persisting execution checkpoints.
Implementations must be safe to call concurrently for different checkpoint IDs and must persist atomically enough that a crash never leaves a partially-written checkpoint.
The optional owner scopes a checkpoint to a user/session/tenant.
Two checkpoints with the same ID but different owners never collide.
When omitted the default owner (:data:DEFAULT_OWNER, "default")
is used, keeping single-tenant callers unchanged.
Use a distinct owner per end-user (e.g. a user id or session id) so
every tenant's runs are isolated from the others and can be listed
with :meth:list.
Methods:
| Name | Description |
|---|---|
cleanup |
Delete stale checkpoints; returns how many were removed. |
delete |
Remove a saved checkpoint. No-op if it does not exist. |
list |
Return all checkpoint IDs persisted for owner. |
load |
Return the saved checkpoint for owner, or |
save |
Persist checkpoint under checkpoint_id for owner. |
Source code in teff/checkpoint/base.py
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 | |
cleanup
async
¶
cleanup(*, owner=None, max_age=None, keep_last=None)
Delete stale checkpoints; returns how many were removed.
owner=None cleans up every owner; otherwise only that owner.
max_age removes checkpoints last written more than that many
seconds ago. keep_last retains the N most recently written
checkpoints per owner (after any max_age pruning) and deletes
the rest. When both are omitted nothing is deleted.
Source code in teff/checkpoint/base.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
delete
async
¶
delete(checkpoint_id, *, owner=DEFAULT_OWNER)
Remove a saved checkpoint. No-op if it does not exist.
Source code in teff/checkpoint/base.py
59 60 61 | |
list
async
¶
list(owner=DEFAULT_OWNER)
Return all checkpoint IDs persisted for owner.
Source code in teff/checkpoint/base.py
63 64 65 | |
load
async
¶
load(checkpoint_id, *, owner=DEFAULT_OWNER)
Return the saved checkpoint for owner, or None if never saved.
Source code in teff/checkpoint/base.py
53 54 55 56 57 | |
save
async
¶
save(checkpoint_id, checkpoint, *, owner=DEFAULT_OWNER)
Persist checkpoint under checkpoint_id for owner.
Source code in teff/checkpoint/base.py
47 48 49 50 51 | |
checkpoint_from_dict
¶
checkpoint_from_dict(data)
Reconstruct a checkpoint from a dict produced by :func:checkpoint_to_dict.
Source code in teff/checkpoint/base.py
94 95 96 97 98 99 100 | |
checkpoint_to_dict
¶
checkpoint_to_dict(cp)
Convert a checkpoint to a JSON-serializable dict.
Source code in teff/checkpoint/base.py
85 86 87 88 89 90 91 | |