Static
connectConnects and links a worker function to the mesh
Static
cronSchedules 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.
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 * * *' }
});
Static
execCalls a function and returns the response.
Static
flushClears a cached function response.
Static
interruptInterrupts a running cron job. Returns true
if the job
was successfully interrupted, or false
if the job was not
found.
Static
shutdown
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).
Example