uniqc.task.persistence module#
Task persistence (legacy dict-based API) backed by the SQLite TaskStore.
Historically this module offered a JSONL-based TaskPersistence class.
All storage has been unified onto uniqc.task.store.TaskStore
(SQLite); this module now provides a thin compatibility layer that keeps
the same flat-dict interface (platform/status/result + extra
keyword metadata).
Usage:
from uniqc.task.persistence import TaskPersistence
persistence = TaskPersistence()
# Save a task
persistence.save(
task_id="task-123",
platform="originq",
status="success",
result={"counts": {"00": 512, "11": 488}},
shots=1000,
)
# Load a task
record = persistence.load("task-123")
# List all tasks for a platform
tasks = persistence.list_all(platform="originq")
- class uniqc.task.persistence.TaskPersistence(cache_dir=None)[source]#
Bases:
objectDict-shaped task store backed by SQLite.
The dict schema exposed to callers uses
platformas the field name for the backend (kept for backward compatibility with pre-unification callers). Internally, records are stored in the shared SQLite database managed byTaskStore.- Variables:
cache_dir – Directory containing
tasks.sqlite.tasks_file – Path to the SQLite database (legacy name preserved for callers that introspect the storage file).
- Parameters:
cache_dir (Optional[Path])
Example
>>> persistence = TaskPersistence() >>> persistence.save("task-1", "originq", "running") >>> record = persistence.load("task-1") >>> print(record['status']) 'running'
- clear_completed()[source]#
Remove records whose status is terminal. Returns count removed.
- Return type:
- save(task_id, platform, status, result=None, **metadata)[source]#
Save (upsert) a task record.
- Parameters:
task_id (str) – Unique task identifier.
platform (str) – Platform / backend name.
status (str) – Task status (‘pending’, ‘running’, ‘success’, ‘failed’).
**metadata (Any) – Extra fields.
shots,submit_time,update_timeare recognised and promoted onto TaskInfo; anything else is stored inTaskInfo.metadata.
- Return type:
None