Module - Cron
You wan to execute a function regularly? This module is for you! It’s using cron package in the background with a few things on top (You start to be used to it in firstly 😉).
Once you have it setup, assign you the role Cron.Admin
(You can get it via
Roles_Cron.Cron_Admin
), and in Admin UI, you will be able to see all crons in the entity named
FF Crons
.
Installation
Section titled “Installation”npm add firstly@latest -D
import { cron, cronTime } from 'firstly/cron/server'
export const api = remultApi({ modules: [ cron([ { // REQUIRED topic: 'first_cron', // Will be used for logs cronTime: cronTime.every_second, // You can use the cron syntax `* * * * * *` or some built in helpers. onTick: () => { console.log('hello') return { status: 'success' } // Must return a Record<string, any> }, // onTick: fnUpdateFormSomewhereElse // Usually doing this in real life !
// OPTIONAL (but you want them 😉) start: !dev // Start in production // runOnInit: dev, // nice in dev environement
// OPTIONAL concurrent: 1, // Default is 1, if we are at the limit, the job will be skipped. logs: {}, // to log more or less stuff, I let you look the ts definition. } ]) ]})