Hangfire: Can you support timed task processing for seconds level units?

Created on 13 Sep 2018  路  8Comments  路  Source: HangfireIO/Hangfire

Is it possible to support seconds of time task processing, or does Hangfire support minutes or more of time task processing?

core enhancement

Most helpful comment

You can look at the IBackgroundProcess interface. IMO its a better way to run tasks that needs to run that frequently since it allow you to fully control how often to run.

Version 1.7 will support expressions that includes seconds by using Cronos instead of NCrontab

All 8 comments

I've had a _very_ quick look; it looks like the cron expression as a string handled by RecurringJobManager does not support seconds. See CronExpression.Parse(cronExpression)

It would seem possible if the cron parsing handled seconds, but perhaps there is a reason this isn't supported.

I'm tempted to dig into this a bit more and pass a CronExpression object to RecurringJobManager.AddOrUpdate rather than a string and cascade accordingly.

Its not so much a matter of the Manager not supporting seconds, than Cron Expressions by nature doesn't support seconds.

https://en.wikipedia.org/wiki/Cron#CRON_expression

That's not supported, can't it be supported in a different way, there are a lot of tasks that need to be done in seconds, so you can't use Hangfire, Quartz. NET can support it, I believe Hangfire can do it, or learn how Quartz does it

You can look at the IBackgroundProcess interface. IMO its a better way to run tasks that needs to run that frequently since it allow you to fully control how often to run.

Version 1.7 will support expressions that includes seconds by using Cronos instead of NCrontab

How can we use the Cronos seconds expression for the RecurringJob.AddOrUpdate function? Is is already supported?

@vindberg even with seconds in cron expression, it still won't give you a second resolution for your jobs because the throttler for recurring jobs would still trigger on a minute basis.

Ok, thanks for the feedback. Am using hostedservice in core now.

Support for seconds implemented in the latest betas of 1.7.0 so you can just pass six-part cron expression and it will work. However, you'll need to tweak the BackgroundJobServerOptions.SchedulePollingInteval option correspondingly to avoid extra delays, because default polling interval is 15 seconds.

Was this page helpful?
0 / 5 - 0 ratings