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.
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.
Hangfire supports cron based expressions… http://docs.hangfire.io/en/latest/background-methods/performing-recurrent-tasks.html
Yes, but Cron expressions’ minimum interval is 1 minute and I need X seconds.
@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.
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.
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.
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 cron - Wikipedia
GitHub - HangfireIO/Cronos: Fully-featured .NET library for working with Cron expressions. Built with time zones in mind and intuitively handles daylight saving time transitions support optionally seconds.