Recuring job every X seconds


#1

Hello!

How do I make a job run every X seconds? The minimum interval for cron expression is 1 minute, so is this impossible?

Thanks in advance for your help.


#2

Hangfire supports cron based expressions… http://docs.hangfire.io/en/latest/background-methods/performing-recurrent-tasks.html


#3

Yes, but Cron expressions’ minimum interval is 1 minute and I need X seconds.


#4

@Veronika: I am looking for the same concept. I am wanting to have a recurring job every 12 hours. I have had a look at the documentation, yet cannot find the correct way to do this.


#5

Please, try this:

RecurringJob.AddOrUpdate(() => job.Do(), "* 12 * * *")

“* 12 * * *” - it is the Cron expression which will be recurring every 12 hours. I hope this will help you.


#6

This is not correct. This cron expression will run every minute from 12:00:00 till 12:59:00. The correct expression is 0 */12 * * *. As for recurring jobs every few seconds, it is not supported by Cron and would be highly inefficient if it were.

By the way, if anyone’s having difficulties with the cron syntax, you can try the Crontab Generator visual tool - http://www.crontab-generator.org.


#7

In some uses of the CRON format there is also a seconds field at the beginning of the pattern. In that case, the CRON expression is a string comprising 6 or 7 fields.

From https://en.m.wikipedia.org/wiki/Cron

https://github.com/HangfireIO/Cronos/ support optionally seconds.