Skip to content

xtr_lock.bundle

The xtr-dependency-injection bundle for xtr-lock.

LOCK_CHANNEL module-attribute

LOCK_CHANNEL = 'lock'

The logging channel locks write to.

DEFAULT_RESOURCE module-attribute

DEFAULT_RESOURCE = 'default'

The resource whose factory is provided without a qualifier.

StoreEntry

StoreEntry = str | Reference

One store: a DSN or keyword :class:~xtr_lock.store.StoreFactory reads, or a connection.

LockBundle

Bases: Bundle[LockConfig]

Turns a :class:LockConfig into a store and a lock factory per resource.

prepend_extension

prepend_extension(builder: ContainerBuilder) -> None

When logging is active, add the lock channel to its config.

load_extension

load_extension(config: LockConfig, services: ServiceConfigurator, builder: ContainerBuilder) -> None

Register a store and a lock factory under each resource's name.

The lock directory is read from the builder, not from the container when a store is built: a container compiled without the kernel's parameters — plain wireup — still gets the project's own directory.

boot async

boot() -> None

Refuse a store no DSN serves, or a connection nobody registered, before any lock.

The configuration is read resolved, so a DSN given as env(...) is read here, and a variable that is not set fails the boot.

Raises:

LockConfig dataclass

LockConfig(resources: Mapping[str, StoreEntry | Sequence[StoreEntry]] = _default_resources())

Which lock resources exist, and which stores keep each one's locks.

Every resource becomes a :class:~xtr_lock.lock_factory.LockFactory qualified by its name, the one named "default" also without a qualifier. A resource with several stores keeps each lock in all of them and counts it held once a majority agree.

A store is one of:

  • "flock" — files in lock under the kernel's share_dir, var/share in the project;
  • any DSN :meth:~xtr_lock.store.StoreFactory.create_store reads — "flock:///var/lock/app", "in-memory", "null", "redis://host:6379" and the like — including env(...);
  • a :class:Reference to a client the container provides.
LockConfig(
    resources={
        "default": "flock",
        "invoices": ["redis://a:6379", "redis://b:6379", "redis://c:6379"],
    }
)

Attributes:

stores_by_resource

stores_by_resource() -> dict[str, tuple[StoreEntry, ...]]

Return each resource's stores as a tuple; the default resource when none is set.