uniqc.backend_adapter.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.backend_adapter.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.backend_adapter.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.backend_adapter.task.persistence.TaskPersistence(cache_dir=None)[source]

Bases: object

Dict-shaped task store backed by SQLite.

The dict schema exposed to callers uses platform as the field name for the backend (kept for backward compatibility with pre-unification callers). Internally, records are stored in the shared SQLite database managed by TaskStore.

Variables:
  • cache_dir – Directory containing tasks.sqlite.

  • tasks_file – Path to the SQLite database (legacy name preserved for callers that introspect the storage file).

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.

count(platform=None, status=None)[source]

Count records with optional filters.

delete(task_id)[source]

Delete a record by id. Returns True if it existed.

list_all(platform=None, status=None, limit=None)[source]

List records, newest first.

Parameters:
  • platform – Filter by platform / backend name.

  • status – Filter by status.

  • limit – Max number of records.

list_by_platform(platform)[source]

All records for a given platform.

list_pending()[source]

Records currently in-flight (‘pending’ or ‘running’).

load(task_id)[source]

Load a record by task id.

save(task_id, platform, status, result=None, **metadata)[source]

Save (upsert) a task record.

Parameters:
  • task_id – Unique task identifier.

  • platform – Platform / backend name.

  • status – Task status (‘pending’, ‘running’, ‘success’, ‘failed’).

  • result – Optional result dict.

  • **metadata – Extra fields. shots, submit_time, update_time are recognised and promoted onto TaskInfo; anything else is stored in TaskInfo.metadata.

update(task_id, **updates)[source]

Update an existing record. update_time is refreshed.

Returns True if the record existed and was updated.

upsert(task_id, platform, status, result=None, **metadata)[source]

Update if present, otherwise insert.