StaticconnectConnects and links a worker function to the mesh
StaticcronSchedules 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 { Client as Postgres } from 'pg';
import { MeshCall } from '@hotmesh/meshcall';
MeshCall.cron({
  topic: 'my.cron.function',
  args: ['arg1', 'arg2'], //optionally pass args
  connection: {
    class: Postgres,
    options: { connectionString: 'postgresql://usr:pwd@localhost:5432/db' }
  },
  callback: async (arg1: any, arg2: any) => {
    //your code here...
  },
  options: { id: 'myDailyCron123', interval: '0 0 * * *' }
});
StaticexecCalls a function and returns the response.
StaticflushClears a cached function response.
Statichashconnection re-use is important when making repeated calls, but only if the connection options are an exact match. this method hashes the connection options to ensure that the same connection
StaticinterruptInterrupts a running cron job. Returns true if the job
was successfully interrupted, or false if the job was not
found.
Staticshutdown
MeshCall connects any function as an idempotent endpoint. Call functions from anywhere on the network connected to the target backend (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 Postgres as the backend provider).
Example