Scheduling is easily done with Cron in json:
{
"CronScheduling": {
"Name": "Periodic Scheduler",
"Expression": "0 5 ? * *",
"AutoStart": true
}
}
Scheduling with PeriodicScheduler is as easy as:
while (!cancellationToken.IsCancellationRequested)
{
try
{
await _taskScheduler.WaitForScheduledStartAsync(cancellationToken);
await ExecuteScopedProcessAsync(cancellationToken);
}
catch (OperationCanceledException)
{
_logger.LogTrace("Periodic timer cancelled");
}
catch (Exception ex)
{
_logger.LogError(ex, "Periodic task failed, waiting for scheduled retry");
}
}