Skip to content

Warmup and health

The data behind FrozenContainer.warmup() / awarmup() and FrozenContainer.checks() / health() / ahealth().

WarmupReport dataclass

What a FrozenContainer.warmup call did, node by node.

Both tuples are in resolution order, and both hold the same GraphNode the dependency graph exposes, so a caller reads a warmed provider's key, scope, shape, and dependencies off the node it already has.

Attributes:

Name Type Description
constructed tuple[GraphNode, ...]

Singletons this call built.

cached tuple[GraphNode, ...]

Singletons that were already built when the call began.

Example
>>> from depin import Container
>>> class Config: ...
>>> di = Container().bind(Config).freeze()
>>> report = di.warmup()
>>> [node.key.__qualname__ for node in report.constructed]
['Config']
>>> di.warmup().cached == report.constructed
True

HealthCheck dataclass

A verification callable a binding declared, as data.

Attributes:

Name Type Description
key ProviderKey

The provider whose value the check verifies.

tag str | None

That provider's tag, when it has one.

needs_async bool

Whether running it requires an event loop, because the provider needs async resolution or the check is a coroutine function.

Example
>>> from depin import Container
>>> class Database: ...
>>> def ping(db: Database) -> None: ...
>>> di = Container().bind(Database, check=ping).freeze()
>>> check = di.checks()[0]
>>> check.key.__qualname__, check.tag, check.needs_async
('Database', None, False)

HealthResult dataclass

What one check said.

Attributes:

Name Type Description
key ProviderKey

The provider whose value was verified.

tag str | None

That provider's tag, when it has one.

healthy bool

False when the check raised or returned False.

error Exception | None

The exception the check raised, when it raised one.

Example
>>> from depin import Container
>>> class Database:
...     ready = False
>>> def ping(db: Database) -> bool:
...     return db.ready
>>> di = Container().bind(Database, check=ping).freeze()
>>> result = di.health().results[0]
>>> result.key.__qualname__, result.healthy, result.error
('Database', False, None)

HealthReport dataclass

Every check's outcome, in resolution order.

Example
>>> from depin import Container
>>> class Database:
...     ready = True
>>> def ping(db: Database) -> bool:
...     return db.ready
>>> di = Container().bind(Database, check=ping).freeze()
>>> report = di.health()
>>> report.healthy, len(report.results)
(True, 1)

healthy property

healthy: bool

Whether every check passed. An empty report is healthy.