> This page is for Remediation Orchestrator.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/remediation-orchestrator/llms.txt.

# patterns

**Experimental.** For evaluation. Interfaces, configuration, and behavior may change incompatibly.

Provides workflow control flow and event-driven concurrency.

### Prerequisites

* None.

### Setup

* Loads automatically. No configuration needed.

* [Module documentation](https://github.com/dsx-ai-factory/remediation-orchestrator/blob/1785e695a8bff76c910115b3c96398a5a59a7183/modules/patterns/README.md).

Provides common patterns for flow control and data types.
Each pattern defines a mapping from a control case to a handler for that case. Patterns may be nested and, will cihild patterns will be provided with details about the case that was selected by the parent.
Cases may be functions, which receive a precursor object detailing any previous selections. The returned value is used for selection purposes.
Each handler is a function that receives a single value, the precursor, that provides information about the case that was chosen. The return value for the handler is pattern specific. See each pattern's documentation for additional details.

## Members

* [halt](#halt)
* [deadline](#deadline)
* [pool](#pool)
* [select](#select)
* [semaphore](#semaphore)
* [sequence](#sequence)
* [spawn](#spawn)
* [switch](#switch)
* [timeout](#timeout)
* [wait](#wait)

## halt

A value compelling patterns to halt iterating through cases.

## deadline

Create a deadline event source that fires once, at a fixed duration from now. Unlike patterns.timeout(), the deadline is not reset when other branches fire in a patterns.select() loop — the timer starts when patterns.deadline() is called and is shared across all iterations of a patterns.sequence().

Time until the deadline expires (e.g. "30s", "5m", "1h").

An event source that fires once, at the absolute deadline.

## pool

Map an iterable through a function with bounded concurrency. Returns an iterable that yields results in completion order.

A title for the pool scenario, used for identification in logs.

An iterable of items to process.

A callable that takes an item and returns an EventSourceProvider (or any value for pass-through).

Max concurrent operations. 0 or omitted = unbounded.

An iterable that yields results in completion order.

## select

Use an event driven architecture to invoke handlers based on workflow signals. A dict provides mapping from events to event handlers. Each key is an event source, provided by other modules, to represent events within their lifecycles. The handler may return any value, which will be returned by the select() call. When until is set, select loops until any handler returns that value.

A title for the scenario. This is used to disambiguate and identify scenarios in a script.

Mapping from events to a handler for the event.

An identifier for the pattern. May be used by downstream consumers to differentiate scenarios.

Loop until any handler returns this value. Defaults to None (single-shot).

The final value.

## semaphore

Create a bounded concurrency semaphore. Use with patterns.wait() or patterns.select() to acquire a token, and call release() to return it.

The maximum number of concurrent tokens.

A semaphore that can be used as an event source.

## sequence

Use a state-machine like architecture to drive behavior. Each step provides the next step in the sequence or a value to return. The key values of the provided dict specifies the set of steps in the sequence. Each dict value defines a handler that may do some work, but returns the next step to execute. If the returned value is not in the dict, then the value is returned from the sequence() call. patterns.sequence("state machine example", \{ "start": "state1", "state1": lambda p: state1_handler(p), "state2": "state1", "state3": patterns.halt, }, start="start", strict=True)

A title for the scenario. This is used to disambiguate and identify scenarios in a script.

A mapping of states that make up the sequence. Each value is either a value that is a key in the map, a function that will compute a key or value that will be returned.

An identifier for the pattern. May be used by downstream consumers to differentiate scenarios.

The starting step. None by default.

If true, fail for unknown values.

The final value.

## spawn

Launch a function asynchronously in a Temporal coroutine. Returns an event source that fires when the function completes. Use with patterns.select() or patterns.wait() to collect the result.

A callable (typically a lambda) to execute asynchronously. The function may call activities, read from Jira, etc.

An event source that fires when the function completes. p.value in handlers is the function's return value.

## switch

Utilize a switch-like pattern where multiple conditions are evaluated. An operand value is provided and compared against the keys of the provided dict. The first match with trigger the corresponding handler. Because both the operand and the keys may be functions, complex logic can be presented in a compact form. patterns.switch("example", True, \{ False: "this won't be matched", lambda p: True: "this will be matched", })

A title for the scenario. This is used to disambiguate and identify scenarios in a script.

A value or function that provides the value to choose from.

A mapping of states that make up the sequence. Each value is either a value that is a key in the map, a function that will compute a key or value that will be returned.

An identifier for the pattern. May be used by downstream consumers to differentiate scenarios.

The starting step.

The final value.

## timeout

Create a timeout event source that fires after the given duration. Use with patterns.select() or patterns.wait().

The duration to wait (e.g. "30s", "5m", "24h").

An event source that fires when the timeout expires.

## wait

Wait for a single event source to fire, with an optional timeout. Returns the resolved value on success, None on timeout. Sugar over patterns.select().

A title for the wait scenario, used for identification in logs and traces.

An event source to wait on (e.g. from patterns.spawn(), interact.form(), wi.case_jql()).

Optional timeout duration (e.g. "30s", "5m"). Returns None if the timeout fires before the event source.

The resolved value from the event source, or None on timeout.