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 WrappableSourcePlug {
    addCredits?: (credits: number) => Promise<number>;
    ingestData?: (size: number) => Promise<OpenJobRequest | OpenJobRequest[]>;
    init?: () => void;
    metrics?: Registry<"text/plain; version=0.0.4; charset=utf-8">;
    pause?: () => void;
    postConsume: (jobId: string) => Promise<undefined | string>;
    start: () => Promise<void>;
    stop: () => Promise<void>;
    on(
        event: "error" | "status" | "data",
        listener: (...args: any[]) => void,
    ): this;
}

Hierarchy (View Summary)

Properties

addCredits?: (credits: number) => Promise<number>

Add new credits to the source

Type declaration

    • (credits: number): Promise<number>
    • Parameters

      • credits: number

        Credits to be added to the source

      Returns Promise<number>

ingestData?: (size: number) => Promise<OpenJobRequest | OpenJobRequest[]>

Perform the ingestion of new jobs

Type declaration

init?: () => void

Enable consuming process

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

Metrics registry for this component

pause?: () => void

Stop consuming process

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
start: () => Promise<void>

Start the Plug and the underlayer resources, making it available

stop: () => Promise<void>

Stop the Plug and the underlayer resources, making it unavailable

Methods

  • Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

    server.on('connection', (stream) => {
    console.log('someone connected!');
    });

    Returns a reference to the EventEmitter, so that calls can be chained.

    By default, event listeners are invoked in the order they are added. The emitter.prependListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.

    import { EventEmitter } from 'node:events';
    const myEE = new EventEmitter();
    myEE.on('foo', () => console.log('a'));
    myEE.prependListener('foo', () => console.log('b'));
    myEE.emit('foo');
    // Prints:
    // b
    // a

    Parameters

    • event: "error" | "status" | "data"
    • listener: (...args: any[]) => void

      The callback function

    Returns this

    v0.1.101