Job scheduler
The configuration of setting a scheduled job
CRON(*) expression is used for job scheduler. The configuration is configured in the schedule class or can be configured, overridden by setting the policy in web.config (for MVC sites) or appsettings.json (for MVC Core). This schedule class should implement ICronScheduleJob interface.
[CronScheduler("Litium.Auditing.CleanupScheduler",
DefaultCronExpression = "0 0/1 * 1/1 * ? *",
Parameter = "param1=text",
ExecutionRestriction = ScheduleCronJobExecutionRestriction.None,
Demand = "Worker")]
public class AuditCleanupJob : ICronScheduleJob
{
async ValueTask ICronScheduleJob.ExecuteAsync(object parameter, CancellationToken cancellationToken)
{
//do something
}
}
The CronScheduler attribute contains 5 parameters:
- The policy name which is defined at appsettings.json.
- The default cron expression will be used when no cron expression is defined.
- The cron time zone for the scheduler policy, with no time zone defined, default is UTC.
- The parameter that will be used when execute job.
- The execution restriction that can disallow concurrent executions on local machine or disallow concurrent execution in the cluster of applications (distributed lock). User can define it as none.
- The demand that will be used to schedule the job into the correct workload instance. If demand not is set and execution restriction is DisallowConcurrentDistributedExecution the demand fallback to Worker. The default allowed values are defined in Litium.Runtime.SystemCapabilities, other values can be allowed to use in agreement with Litium Support.
The list of policy name must be configured in Litium.Accelerator.Mvc - appsettings.json under Litium node.
"Litium": {
"Scheduler": {
"Policy": {
"Litium.Auditing.CleanupScheduler": {
"CronExpression": "0 0/1 * 1/1 * ? *",
"Parameter": "param1=text",
"CronTimeZone": "Central Standard Time",
"Demand": "Worker"
}
}
}
}
To override an exsiting scheduler, the policy name in config file must be the same as the name of the scheduler.
For instance, user want to change the cron expression of the exsiting AuditCleanupJob was defined with policy name is Litium.Auditing.CleanupJob to make it run every five minutes. Then user can add more policy to Policy in config file.
"Policy": {
"Litium.Auditing.CleanupJob": { "CronExpression": "0 0/5 * * * ?" }
}