lacing.worker#

Optional Arq integration — queue processors through Redis.

This module imports arq only when needed, so it’s safe to import even without [arq] installed. The actual WorkerSettings class is constructed lazily by build_worker_settings().

Usage:

# In a worker process — assumes Redis is running.
import asyncio
from lacing.worker import build_worker_settings
from arq import run_worker

settings = build_worker_settings(
    store_factory=lambda: SqliteStore("project.annot", check_same_thread=False),
    oplog_factory=lambda: SqliteOpLog("project.annot.oplog", check_same_thread=False),
)
run_worker(settings)

# In your app — enqueue a processor:
from arq.connections import create_pool, RedisSettings

redis = await create_pool(RedisSettings())
await redis.enqueue_job(
    "run_processor",
    "low_confidence_review",
    threshold=0.4,
)

For testing and small-scale work, prefer lacing.processors.run_sync() — it runs the same registered processor in the current event loop with no Redis needed.

Functions

build_worker_settings(*, store_factory, ...)

Build an Arq WorkerSettings class with lacing processors registered.

lacing.worker.build_worker_settings(*, store_factory, oplog_factory, redis_settings=None)[source]#

Build an Arq WorkerSettings class with lacing processors registered.

Parameters:
  • store_factory (Callable[[], Any]) – Zero-arg callable returning a fresh IntervalAnnotationStore (per-job; processors mutate it).

  • oplog_factory (Callable[[], Any]) – Zero-arg callable returning a fresh OpLog.

  • redis_settings (Any | None) – Optional arq.connections.RedisSettings.

Return type:

type

Returns:

A class suitable for arq.run_worker(...).