JVM - schedule.cron()
Sets the cron expressions that determines when the schedule triggers and a callback to be triggered.
import io.nitric.Nitric;import io.nitric.faas.v0.Frequency;public class Application {public static void main(String[] args) {// Create a schedule that runs at 1:00am on the 1st of every monthNitric.INSTANCE.schedule("send-reminder").cron("0 1 1 * *", (ctx) -> {// add code to run herereturn ctx;});Nitric.run();}}
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 List<EventMiddleware>
- Description
One or more callback functions to use as the handler which will run on the defined frequency.
Examples
Create a Schedule
import io.nitric.Nitric;import io.nitric.faas.v0.Frequency;public class Application {public static void main(String[] args) {// every 15 minutesNitric.INSTANCE.schedule("check for updates").cron("0/15 * * * *", (ctx) -> {System.out.println("checking for updates");return ctx;});// at 1:00am on the 1st of every monthNitric.INSTANCE.schedule("delete stale data").cron("0 1 1 * *", (ctx) -> {System.out.println("clearing data");return ctx;});Nitric.run();}}
Last updated on Jan 14, 2025