The C# .NET SDK currently only supports legacy versions of Nitric prior to v1. This version is maintained for compatibility with existing projects and not recommended for new projects. New projects should be started using a supported SDK (presented automatically using the `nitric new` command) orget in touch to request an update to the latest version.
.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 processing
return 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 processing
return context;
});
Nitric.Run();
Create a Schedule with multiple middleware/handlers
using Nitric.Sdk;
using Nitric.Sdk.Function;
// Create a middleware to handle report generation
private EventContext GenerateReport(EventContext ctx, Func<EventContext, EventContext> next)
{
// Code to generate a report
return next(ctx);
}
// Create a middleware to handle notifications
private EventContext SendNotification(EventContext ctx, Func<EventContext, EventContext> next)
{
// Code to send a notification
return next(ctx);
}
// Create a schedule that runs every 7 days
Nitric.Schedule("send-reminder").Every(7, Frequency.Days, GenerateReport, SendNotification);
Nitric.Run();