Interface Base<Type, Data, CustomHeaders, CustomOptions>

A resource is extended component that represent the access to an external/internal resource, besides the error handling and identity, it has a start, stop and close methods to manage the resource lifecycle. It also has a checks property to define the checks that will be performed over the resource to achieve the resulted status. The most typical example of a resource are the Provider that allow to access to external databases, message brokers, etc.

interface Base<
    Type extends string = string,
    Data = any,
    CustomHeaders extends Record<string, any> = AnyHeaders,
    CustomOptions extends Record<string, any> = AnyOptions,
> {
    metrics?: Registry<"text/plain; version=0.0.4; charset=utf-8">;
    postConsume: (jobId: string) => Promise<undefined | string>;
    on(event: "error", listener: (error: Crash | Error) => void): this;
    on(
        event: "status",
        listener: (status: "pass" | "fail" | "warn") => void,
    ): this;
    on(
        event: "data",
        listener: (
            job: JobRequest<Type, Data, CustomHeaders, CustomOptions>,
        ) => void,
    ): this;
    start(): Promise<void>;
    stop(): Promise<void>;
}

Type Parameters

  • Type extends string = string
  • Data = any
  • CustomHeaders extends Record<string, any> = AnyHeaders
  • CustomOptions extends Record<string, any> = AnyOptions

Hierarchy (View Summary)

Properties

Methods

Properties

metrics?: Registry<"text/plain; version=0.0.4; charset=utf-8">

Metrics registry for this component

postConsume: (jobId: string) => Promise<undefined | string>

Perform the task to clean the job registers after the job has been resolved

Type declaration

    • (jobId: string): Promise<undefined | string>
    • Parameters

      • jobId: string

        Job entry identification

      Returns Promise<undefined | string>

      • the job entry identification that has been correctly removed or undefined if the job was not found

Methods

  • Emitted when the component throw an error

    Parameters

    • event: "error"
    • listener: (error: Crash | Error) => void

    Returns this

  • Emitted on every status change

    Parameters

    • event: "status"
    • listener: (status: "pass" | "fail" | "warn") => void

    Returns this

  • Emitted when there is a new job to be managed

    Parameters

    Returns this

  • Start the Plug and the underlayer resources, making it available

    Returns Promise<void>

  • Stop the Plug and the underlayer resources, making it unavailable

    Returns Promise<void>