GitHub

durable_clock

API reference for durable_clock.

Durable sleeps of a workflow (Effect's effect/workflow/DurableClock)::

yield from durable_clock.sleep(name="cool-off", duration="3 days")

A sleep longer than in_memory_threshold (default InMemoryThreshold, 60 seconds) is scheduled with the engine and suspends the execution until the clock wakes it; a shorter one runs as an activity sleeping in memory.

Values

AttributeTypeDescription
DEFAULT_IN_MEMORY_THRESHOLDDuration

Classes

Functions

make

make(*, name, duration) -> DurableClock
ParameterTypeDescription
namestr
durationDurationInput

Returns DurableClock

def make(*, name: str, duration: DurationInput) -> DurableClock:
    return DurableClock(
        name=name,
        duration=from_input_unsafe(duration),
        deferred=make_deferred(f"DurableClock/{name}"),
    )

sleep

sleep(*, name, duration, in_memory_threshold=None) -> Effect[None, Never, WorkflowEngine | WorkflowInstance]

Wait duration inside a workflow. A zero duration does nothing.

ParameterTypeDescription
namestr
durationDurationInput
in_memory_thresholdDurationInput | None = None

Returns Effect[None, Never, WorkflowEngine | WorkflowInstance]

def sleep(
    *, name: str, duration: DurationInput, in_memory_threshold: DurationInput | None = None
) -> Effect[None, Never, WorkflowEngine | WorkflowInstance]:
    """Wait ``duration`` inside a workflow. A zero duration does nothing."""
    parsed = from_input_unsafe(duration)
    if parsed.is_zero():
        return succeed(None)
    if in_memory_threshold is None:
        return InMemoryThreshold().flat_map(lambda threshold: _sleep(name, parsed, threshold))
    return _sleep(name, parsed, from_input_unsafe(in_memory_threshold))