Skip to content

duron.contrib module

codecs

PickleCodec

A codec that uses Python's pickle module for serialization and deserialization.

storage

FileLogStorage

FileLogStorage(log_file)

A log storage that uses a file to store log entries.

MemoryLogStorage

MemoryLogStorage(entries=None)

A log storage that keeps log entries in memory.

SQLiteLog

SQLiteLog(db_path, task_id)

A log storage for a single task in a SQLite database.

Implements multiprocess-safe lease mechanism using database-backed leases. Last acquirer wins - lease is only validated on append.

acquire_lease async

acquire_lease()

Acquire a lease for this task log.

Uses database-backed leases for multiprocess coordination. Last acquirer wins - replaces any existing lease.

Returns:

  • bytes

    A lease token that must be provided to append() and release_lease().

append async

append(token, entry)

Append an entry to the log.

Validates the lease before appending. Raises ValueError if invalid.

Parameters:

  • token (bytes) –

    The lease token returned by acquire_lease().

  • entry (Entry) –

    The log entry to append.

Returns:

  • int

    The offset (ROWID) of the appended entry.

release_lease async

release_lease(token)

Release a previously acquired lease.

Parameters:

  • token (bytes) –

    The lease token returned by acquire_lease().

SQLiteLogManager

SQLiteLogManager(db_path)

A log manager that stores multiple task logs in a single SQLite database.

Uses WAL mode and database-backed leases for multiprocess support. Last acquirer wins - no expiration tracking.

Initialize the SQLite log manager.

Parameters:

  • db_path (str | Path) –

    Path to the SQLite database file.

create_log async

create_log(task_id)

Create or retrieve a log storage for the given task ID.

Returns:

  • SQLiteLog

    A SQLiteLog instance for the specified task.