bullmq - v6.3.11
    Preparing search index...

    Interface ContextManager<Context>

    Context manager interface

    The context manager is responsible for managing the context and propagating it across the application.

    interface ContextManager<Context = any> {
        active(): Context;
        fromMetadata(activeContext: Context, metadata: string): Context;
        getMetadata(context: Context): string;
        root?(): Context;
        with<A extends (...args: any[]) => any>(
            context: Context,
            fn: A,
        ): ReturnType<A>;
    }

    Type Parameters

    • Context = any
    Index
    • Creates a new context from a serialized version effectively linking the new context to the parent context.

      Parameters

      • activeContext: Context

        the current active context

      • metadata: string

        the serialized version of the context

      Returns Context

    • Returns a serialized version of the current context. The metadata is the mechanism used to propagate the context across a distributed application.

      Parameters

      • context: Context

        the current context

      Returns string

    • Returns an empty context, detached from whatever context is currently active.

      This is used for long lived background loops (such as the stalled jobs checker), which must not inherit the context of whichever call happened to start them. Without it, context managers backed by AsyncLocalStorage would keep every iteration of the loop attached to that original span, producing a single trace that grows for the lifetime of the process.

      Optional: adapters built against older versions of this interface may omit this method. When unavailable, withDetachedContext preserves the active context for backward compatibility.

      Returns Context

    • Creates a new context and sets it as active for the fn passed as last argument

      Type Parameters

      • A extends (...args: any[]) => any

      Parameters

      • context: Context

        the context to set as active

      • fn: A

        the function to execute with the context

      Returns ReturnType<A>