how to write a complex quartz cron expression

995 views Asked by At

i need to develop a web service, that will help the client to do some periodic job, the api will like this void Dojob(int jobType, string cronExpression);

because the client/user will do anything the want, i just want to know does the cron expression support the situation below:

the job will fire in the following times: from 9:10am to 10:50am trigger at every 8 minutes, every day.

from 9:00 to 10:00 maybe easier, but i still cannot find the correct cron Expression about 9:10am to 10:50am.

2

There are 2 answers

0
sgmoore On

Not sure if you can do this using one cron expression, but you can using two.

eg

0 10,18,26,34,42,50,58 9 1/1 * ? *

0 6,14,22,30,38,46 10 1/1 * ? *
0
philr On

As sgmoore said, you cannot do this using 1 cron expression. You'll have to create 2 triggers each with different cron expressions to get this to work.

The first will be from 9:10 to 9:59 every 8 minutes which looks like this:

0 10-59/8 9 1/1 * ? *

The second will be from 10:00 to 10:50 every 8 minutes which looks like this:

0 0-50/8 10 1/1 * ? *

Just be warned that due to how cron expressions work, this will fire every 8 minutes restarting at the top of every hour, therefore firing at both 9:58 and 10:00 in this scenario