Node.js - schedule.cron()
Sets the cron expressions that determines when the schedule triggers and a callback to be triggered.
import { schedule } from '@nitric/sdk'schedule('send-reminder').cron('0 1 1 * *', async (ctx) => {// do some processing})
Parameters
- Name
expression
- Required
- Required
- Type
- string
- Description
The expression that sets when the schedule will be triggered. This value should be a standard 5 value Unix cron expression, e.g., '0 1 1 * *'.
- Name
middleware
- Required
- Required
- Type
- EventMiddleware or EventMiddleware[]
- Description
One or more callback services to use as the handler which will run on the defined frequency.
Examples
Create a Schedule
import { schedule } from '@nitric/sdk'// every 15 minutesschedule('check for updates').cron('0/15 * * * *', async (ctx) => {console.log('checking for updates')})// at 1:00am on the 1st of every monthschedule('delete stale data').cron('0 1 1 * *', async (ctx) => {console.log('clearing data')})
Last updated on Nov 18, 2024