Job Scheduling
Provides scheduled job operations.
Schedule Configurations
Schedule config for scheduling jobs.
Properties | Description |
---|---|
CronExpression | Cron expression of job. |
TimeZoneInfo | Time zone information of job. |
CronFormat | Cron format enum. |
Usage
Create your job class with inherit MilvaCronJobService
.
Override ExecuteAsync
method. This is the method by which the work is done. Write the job you want to schedule in this method.
public class MyCronJob : MilvaCronJobService
{
public MyCronJob(IScheduleConfig scheduleConfig) : base(scheduleConfig)
{
}
public override async Task ExecuteAsync(CancellationToken cancellationToken) => Console.WriteLine("Executed!");
}
Register the required services to service collection.
services.AddMilvaCronJob<MyCronJob>(c =>
{
c.TimeZoneInfo = TimeZoneInfo.Local;
c.CronExpression = @"* * * * * *"; // Every second
c.CronFormat = CronFormat.IncludeSeconds;
});