flow.record.context

Module Contents

Classes

AppContext

Context for the application, holding metrics like amount of processed records.

Functions

get_app_context

Retrieve the application context, creating it if it does not exist.

fresh_app_context

Create a fresh application context for the duration of the with block.

match_record_with_context

Return True if record matches the selector, also keeps track of relevant metrics in context.

Attributes

flow.record.context.APP_CONTEXT: contextvars.ContextVar[AppContext]
flow.record.context.get_app_context() AppContext

Retrieve the application context, creating it if it does not exist.

Returns:

The application context.

flow.record.context.fresh_app_context() collections.abc.Generator[AppContext, None, None]

Create a fresh application context for the duration of the with block.

class flow.record.context.AppContext

Context for the application, holding metrics like amount of processed records.

read: int = 0
matched: int = 0
unmatched: int = 0
source_count: int = 0
source_total: int = 0
flow.record.context.match_record_with_context(record: flow.record.Record, selector: flow.record.selector.Selector | None, context: AppContext) bool

Return True if record matches the selector, also keeps track of relevant metrics in context. If selector is None, it will always return True.

When calling this function, it also increases the context.read property.

Parameters:
  • record – The record to match against the selector.

  • selector – The selector to use for matching.

  • context – The context in which the record is being matched.

Returns:

True if record matches the selector, or if selector is None