MeshCall connects your functions to the Redis-backed mesh, exposing them as idempotent endpoints. Call functions from anywhere on the network with a connection to Redis. Function responses are cacheable and functions can even run as idempotent cron jobs (this one runs once a day).

MeshCall.cron({
topic: 'my.cron.function',
redis: {
class: Redis,
options: { url: 'redis://:key_admin@redis:6379' }
},
callback: async () => {
//your code here...
},
options: { id: 'myDailyCron123', interval: '0 0 * * *' }
});

Methods

  • Connects and links a worker function to the mesh

    Parameters

    Returns Promise<HotMesh>

    MeshCall.connect({
    topic: 'my.function',
    redis: {
    class: Redis,
    options: { url: 'redis://:key_admin@redis:6379' }
    },
    callback: async (arg1: any) => {
    //your code here...
    }
    });
  • Schedules a cron job to run at a specified interval with optional args. Provided arguments are passed to the callback function each time the cron job runs. The id option is used to uniquely identify the cron job, allowing it to be interrupted at any time.

    Parameters

    Returns Promise<boolean>

    MeshCall.cron({
    topic: 'my.cron.function',
    args: ['arg1', 'arg2'], //optionally pass args
    redis: {
    class: Redis,
    options: { url: 'redis://:key_admin@redis:6379' }
    },
    callback: async (arg1: any, arg2: any) => {
    //your code here...
    },
    options: { id: 'myDailyCron123', interval: '0 0 * * *' }
    });
  • Calls a function and returns the response.

    Type Parameters

    • U

      the return type of the linked worker function

    Parameters

    Returns Promise<U>

    const response = await MeshCall.exec({
    topic: 'my.function',
    args: [{ my: 'args' }],
    redis: {
    class: Redis,
    options: { url: 'redis://:key_admin@redis:6379' }
    }
    });
  • Clears a cached function response.

    Parameters

    Returns Promise<void>

    MeshCall.flush({
    topic: 'my.function',
    redis: {
    class: Redis,
    options: { url: 'redis://:key_admin@redis:6379' }
    },
    options: { id: 'myCachedExecFunctionId' }
    });
  • Interrupts a running cron job. Returns true if the job was successfully interrupted, or false if the job was not found.

    Parameters

    Returns Promise<boolean>

    MeshCall.interrupt({
    topic: 'my.cron.function',
    redis: {
    class: Redis,
    options: { url: 'redis://:key_admin@redis:6379' }
    },
    options: { id: 'myDailyCron123' }
    });
  • Shuts down all meshcall instances. Call this method from the SIGTERM handler in your application.

    Returns Promise<void>