.NET - Schedule.Every()
Sets the frequency and one or many handlers to be triggered.
using Nitric.Sdk;using Nitric.Sdk.Function;Nitric.Schedule("send-reminder").Every(3, Frequency.Hours, context =>{// do some processingreturn context;});Nitric.Run();
Parameters
- Name
rate
- Required
- Required
- Type
- string
- Description
The rate to run the schedule, e.g. '7 days'. All rates accept a number and a frequency. Valid frequencies are 'days', 'hours' or 'minutes'.
- Name
middleware
- Required
- Required
- Type
- Func<EventContext, EventContext> or List<Middleware<EventContext>
- Description
One or more middleware functions to use as the handler which will run on defined frequency.
Examples
Create a Schedule to run every 3 minutes
using Nitric.Sdk;using Nitric.Sdk.Function;Nitric.Schedule("send-reminder").Every(3, Frequency.Minutes, context =>{// do some processingreturn context;});Nitric.Run();
Create a Schedule with multiple middleware/handlers
using Nitric.Sdk;using Nitric.Sdk.Function;// Create a middleware to handle report generationprivate EventContext GenerateReport(EventContext ctx, Func<EventContext, EventContext> next){// Code to generate a reportreturn next(ctx);}// Create a middleware to handle notificationsprivate EventContext SendNotification(EventContext ctx, Func<EventContext, EventContext> next){// Code to send a notificationreturn next(ctx);}// Create a schedule that runs every 7 daysNitric.Schedule("send-reminder").Every(7, Frequency.Days, GenerateReport, SendNotification);Nitric.Run();
Last updated on Jan 14, 2025