This sample illustrates a simple example of the built-in scheduler API. Two common use cases are:
- Sending a message.
- Executing some custom code.
The scheduling API is accessed via an instance of IEndpointInstance
.
// Send a message every 5 seconds
await endpointInstance.ScheduleEvery(
timeSpan: TimeSpan.FromSeconds(5),
task: pipelineContext =>
{
var message = new MyMessage();
return pipelineContext.SendLocal(message);
});
// Name a schedule task and invoke it every 5 seconds
await endpointInstance.ScheduleEvery(
timeSpan: TimeSpan.FromSeconds(5),
name: "MyCustomTask",
task: pipelineContext =>
{
log.Info("Custom Task executed");
return Task.CompletedTask;
});