API Maker

The backend engine for the AI era

Your code

Schedulers

Run your code on a timetable, once per cluster, without a cron server.

A scheduler is a function, in any of the 8 languages, plus one or more intervals: every few seconds, every day at midnight, or your own cron. With several servers, each scheduler belongs to one of them, held with a key in Redis, so every run happens once. If that server goes down, another one takes over.

See it live

Step through it, slow it down, or open the full canvas.

api-maker/features/scheduleLive
  • Look
  • Redis key
  • Run
  • Server down
Intervals
22 time zones
Owner
—one server
Runs
0logged
Timeout
10min, this scheduler

A scheduler is your code and its intervals. Write a function with g, in any of the 8 languages, add one or more intervals and press Ctrl + S. It is saved and scheduled: no cron server to set up.

How it works

  1. A scheduler is your code and its intervals.

    Write a function with g, in any of the 8 languages, add one or more intervals and press Ctrl + S. It is saved and scheduled: no cron server to set up.

  2. Presets or cron, in any time zone.

    From every 5 seconds to every year, or your own cron with seconds. Each interval has its time zone and can be switched off.

  3. Many servers, one owner.

    The schedulers are spread evenly over the servers which are up. The server a scheduler belongs to takes it with a key in Redis, so each run happens once in the cluster.

  4. On time, in the sandbox, logged.

    The owner runs your code in a sandbox, with the timeout of the scheduler, and saves the log of each run. It renews its Redis key every 5 seconds.

  5. A server goes down, another takes over.

    A server that stops hands its schedulers over within a second. When it dies, its key is not renewed and runs out after 20 seconds: another server takes the scheduler.

  6. Save, and the next run uses the new code.

    The owner stops its jobs, a run in progress finishes, and the scheduler starts again with the new code. No redeploy.

What you get

Presets for the usual

Every 1, 5, 10, 15 or 30 seconds, every few minutes or hours, every day, working days, every month or every year.

Failover built in

A server which stops hands its schedulers to the others within a second. When it dies, they move within about twenty seconds, when its hold runs out.

Everything g offers

Query and update any database, call external APIs, emit events and use your utility classes, like in a custom API.

An example

Nightly jobs without extra infrastructure

Expire old carts, send a daily sales report by email, sync prices from a supplier API every 15 minutes. Each one is a scheduler in API Maker, versioned with the rest of your project and deployed with it.

Every night: close carts left open for a dayscheduler.ts
import * as T from 'types';async function main(g: T.IAMGlobal) {    const dayAgo = new Date(Date.now() - 24 * 60 * 60 * 1000);    const result = await g.sys.db.updateMany({        instance: 'mongodb', database: 'shop', collection: 'carts',        find: { status: 'open', updatedAt: { $lt: dayAgo } },        updateData: { status: 'expired' },    });    g.logger.log(`${result.updatedRowsCount} carts expired`);}module.exports = main;

Interval: every day, at midnight, Asia/Kolkata. Press Ctrl + S and it is scheduled.

Watch it

On the real admin panel, with real data.

Schedulers: Cron Jobs Without a Cron Server 13 chapters and the transcript

Good to know

  • Schedulers of developer accounts never run in the background. Developers run them by hand from API Maker.
  • A run that passes schedulerTimeoutInMinutes (5 minutes when you set none) is stopped. Raise it for long jobs.

Questions

Can I pause a scheduler?

Yes. Switch the scheduler off, or switch off one of its intervals.

Where does it run?

In a sandbox of its account, on the server which holds it, or on the native process when you allow it.