Reputation: 327
In a .NET Core 5 Web API project I have a job scheduler, which is updating something in the database.
I want to run that job scheduler twice a day at 12 AM and 12 PM. What will be the cron expression for that?
How am I able to run the Quartz job scheduler twice in a day?
Here is the code of scheduler start:
public async Task StartAsync(CancellationToken cancellationToken)
{
Scheduler = await _schedulerFactory.GetScheduler(cancellationToken);
Scheduler.JobFactory = _jobFactory;
var job2 = new JobSchedule(jobType: typeof(MCBJob),
cronExpression: "0 0 0/12 * * ");
var mcbJob = CreateJob(job2);
var mcbTrigger = CreateTrigger(job2);
await Scheduler.ScheduleJob(mcbJob, mcbTrigger, cancellationToken);
await Scheduler.Start(cancellationToken);
}
Upvotes: 1
Views: 1479
Reputation: 97
May be this is helpful in your case.
Visit http://www.cronmaker.com/
CronMaker is a simple website which helps you to build cron expressions. CronMaker uses Quartz open source scheduler. Generated expressions are based on Quartz cron format.
Upvotes: 0
Reputation: 11151
You can separate values with ,
to specify individual values.
https://en.wikipedia.org/wiki/Cron#CRON_expression
4 -> 4
0-4 -> 0,1,2,3,4
*/4 -> 0,4,8,12,...,52,56
0,4 -> 0,4
We can build the schedule now:
0 0 0,12 * *
| | | | every month
| | | every day
| | at hour 0 and 12
| at minute 0
at first second
You can use https://crontab.guru/ to build a cron expression interactively.
Upvotes: 1