MeshCall connects any function as an idempotent endpoint. Call functions from anywhere on the network connected to the target backend (Redis, Postgres, NATS, etc). Function responses are cacheable and invocations can be scheduled to run as idempotent cron jobs (this one runs nightly at midnight and uses Redis as the backend provider).

import * as Redis from 'redis';
import { MeshCall } from '@hotmesh/meshcall';

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

Methods

  • Connects and links a worker function to the mesh

    Parameters

    Returns Promise<HotMesh>

    import * as Redis from 'redis';
    import { MeshCall } from '@hotmesh/meshcall';

    MeshCall.connect({
    topic: 'my.function',
    connection: {
    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>

    import * as Redis from 'redis';
    import { MeshCall } from '@hotmesh/meshcall';

    MeshCall.cron({
    topic: 'my.cron.function',
    args: ['arg1', 'arg2'], //optionally pass args
    connection: {
    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' }],
    connection: {
    class: Redis,
    options: { url: 'redis://:key_admin@redis:6379' }
    }
    });
  • Clears a cached function response.

    Parameters

    Returns Promise<void>

    import * as Redis from 'redis';
    import { MeshCall } from '@hotmesh/meshcall';

    MeshCall.flush({
    topic: 'my.function',
    connection: {
    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>

    import * as Redis from 'redis';
    import { MeshCall } from '@hotmesh/meshcall';

    MeshCall.interrupt({
    topic: 'my.cron.function',
    connection: {
    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>