Allow for cron to include seconds

recurring
Tags: #<Tag:0x00007f69fbcf2080>

#1

The current Cron library in use allows for seconds as a 6th item. Would love to see the option to include seconds in cron statements officially.


#2

Hey tracstarr have I misunderstood you, or are you saving there is currently a way to schedule a job in Hangfire to run every x seconds?

If there is could you explain how?


#3

Not directly using cron right now, now. Although the underlying library does/did allow for seconds. But if i’m not mistaken it’s not in use anymore.

The only way to run every x seconds is to start a scheduled job and have it either wait or kick off a new scheduled job in x seconds.


#4

In my opinion, having a job running every few seconds is totally unreasonable.

First, it is beyond throttler’s resolution, so it will never follow the exact schedule.

Second, it would produce a huge storage overhead because of lots of records inserted and distributed locks’ acquisition.


#5

In the enterprise world, that’s a very legitimate use case. I’m not saying I’d design a system that way when we have so many ways of making reactive apps now, but it’s absolutely a thing.


#6

My application needs to poll new events from external service. We need to do it often, e.g. every 10 sec( but it should be configurable). Can I use Hangfire (and Cron expressions) for this?


#7

I don’t think firing a Hangfire job off every X seconds is a good choice for this kind of application. (Even if Hangfire supported it).

The overhead of firing up a job that often wouldn’t be great. Plus very often polling an external service (like a rest api) can get slow and then cron’s getnextoccurance will wait until the next 10 sec interval (it won’t be a 10 sec rest between runs, it will try to run every 10 “clock” secs even if the job runs long).

I’ve always just had a continuously running process handle this and have it sleep X secs. If its running on Azure use a webjob running a console app in continus mode. If on a windows server create a service that runs and windows will babysit and restart if needed (doesn’t always work so look at good code examples or use a service framework).


#8

Just to help give a complete answer, Hangfire doesn’t yet support continuous tasks but it is being considered for the future.