The cluster workflow engine (Effect's ClusterWorkflowEngine): a
WorkflowEngine whose executions, activities, deferred completions,
resumes, interrupts and durable clocks are persisted cluster entity
messages, so durable workflows survive runner restarts and move with
their shards.
layer provides the engine on Sharding and MessageStorage and
registers the durable clock entity; make builds the engine alone.
Values#
| Attribute | Type | Description |
|---|---|---|
layer | Layer[WorkflowEngine, Never, Sharding | MessageStorage] | The cluster workflow engine on |
Functions#
make#
make() -> Effect[WorkflowEngineService, Never, Sharding | MessageStorage | Scope]A WorkflowEngineService backed by cluster sharding and message
storage (Effect's ClusterWorkflowEngine.make).
Returns Effect[WorkflowEngineService, Never, Sharding | MessageStorage | Scope]
def make() -> Effect[WorkflowEngineService, Never, Sharding | MessageStorage | Scope]:
"""A ``WorkflowEngineService`` backed by cluster sharding and message
storage (Effect's ``ClusterWorkflowEngine.make``)."""
def body() -> Generator[Effect[Any, Any, Any], Any, WorkflowEngineService]:
sharding = yield from Sharding()
storage = yield from MessageStorage()
holder: dict[str, ClusterEngine] = {}
def lookup(workflow_name: str) -> Effect[Callable[[str], Any]]:
engine = holder["engine"]
entity = engine.entities.get(workflow_name)
if entity is None:
return die(RuntimeError(f"Workflow {workflow_name} not registered"))
return engine.clients_partial.invalidate(workflow_name).and_then(
cast("Effect[Callable[[str], Any]]", entity.client())
)
def lookup_partial(workflow_name: str) -> Effect[Callable[[str], Any]]:
engine = holder["engine"]
entity = engine.entities.get(workflow_name) or engine.ensure_partial_entity(
workflow_name
)
return cast("Effect[Callable[[str], Any]]", entity.client())
clients = yield from RcMap.make(lookup, idle_time_to_live="5 minutes")
clients_partial = yield from RcMap.make(lookup_partial, idle_time_to_live="5 minutes")
return ClusterEngine(sharding, storage, clients, clients_partial, holder).service
return cast(
"Effect[WorkflowEngineService, Never, Sharding | MessageStorage | Scope]", gen(body)
)