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.
API Maker
The backend engine for the AI era
Your code
Run your code on a timetable, once per cluster or on every server at once, 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. Or it runs on every server at the same moment, once on each or once in every runner, and the runs share the work with locks.
Step through it, slow it down, or open the full canvas.
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.
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.
From every 5 seconds to every year, or your own cron with seconds. Each interval has its time zone and can be switched off.
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.
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.
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.
The owner stops its jobs, a run in progress finishes, and the scheduler starts again with the new code. No redeploy.
Every 1, 5, 10, 15 or 30 seconds, every few minutes or hours, every day, working days, every month or every year.
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.
Run a scheduler on every server at once, once on each or once in each of its runners: as many runs as the servers have processor cores. g.req.scheduler tells each run its share of the work.
g.sys.system.getLock gives an item to one run of all the servers. The agent of each runner talks to Redis itself, and a waiting run gets the lock the moment it is given back.
Query and update any database, call external APIs, emit events and use your utility classes, like in a custom API.
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.
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.
import * as T from 'types';async function main(g: T.IAMGlobal) { const { worker, workers } = g.req.scheduler; const orders = await g.sys.db.query({ instance: 'mysql_8', database: 'shop', collection: 'orders', find: { status: 'paid' } }); for (const order of orders.filter(order => order.id % workers === worker)) { const lock = await g.sys.system.getLock({ name: `order-${order.id}`, ttlSeconds: 120 }); if (!lock.acquired) continue; try { await g.sys.db.updateById({ instance: 'mysql_8', database: 'shop', collection: 'orders', id: order.id, updateData: { status: 'packed' } }); } finally { await g.sys.system.releaseLock(lock); } }}module.exports = main;Runs on: Every server, once per runner. Each run takes its share, and the lock of each order.
On the real admin panel, with real data.
Yes. Switch the scheduler off, or switch off one of its intervals.
In a sandbox of its account, on the server which holds it, or on the native process when you allow it.
Yes. Set Runs on to Every server: each server runs it at every moment, once, or once in each of its runners. Locks (g.sys.system.getLock) make sure each item is done by one run only.
Documentation