Where is the polling interval variable set and what’s it called in Hangfire source code? What I mean is that each worker thread periodically polls for jobs in Job Storage. For Fire and Forget jobs specifically, where is the polling frequency variable set? I see a “SchedulePollingInterval” in BackgroundJobServerOptions.cs, is this for both fire and forget and schedule/delayed jobs?
Polling interval makes sense only with SQL Server, so this option is available in SqlServerStorageOptions
. Neither MSMQ extension, nor Redis storage implementation use polling, decreasing the latency of background job processing.
What’s are the functions of “SchedulePollingInterval” defined in “BackgroundJobServerOptions.cs” and “QueuePollInterval” defined in “SqlServerStorageOptions.cs”.
QueuePollInterval
option is for fire-and-forget jobs, SchedulePollingInterval
option is for delayed jobs.
Where and how can we alter the QueuePollInterval value?
Please see the corresponding documentation topic – http://docs.hangfire.io/en/latest/configuration/using-sql-server.html#configuring-the-polling-interval
So am I correct if I say, setting QueuePollInterval as no effect on how often delayed jobs are polled and vice versa?
Strictly saying, delayed jobs are being checked by a SchedulePoller first with SchedulePolling interval, after that it is being enqueued and picked by a worker with QueuePollInterval.
In other words, “QueuePollInterval” polls for all Enqueued jobs, regardless if it’s a fire-forget, recurring or delayed/scheduled type?
Hangfire is a carefully disguised state machine. There are a couple of states (Enqueued, Scheduled, Succeeded, Failed, Deleted, soon there will be Awaiting, but there is no Recurring – they are different). Each background job has a state, and when an internal state machine change the state of a background job, it uses a corresponding state handler.
Enqueued state handler adds a job to the job queue. Scheduled state handler adds a job to the scheduled
set. Other may have no state handlers at all.
Job queues are watched by a pool of worker threads. In SQL Server storage implementation there is a table for all the queues that is being checked in a QueuePollInterval
.
scheduled
set is being watched by a single thread, called SchedulePoller. It uses SchedulePollingInterval
to check the jobs needed to run, but instead of performing them in-place, it simply changes their state to enqueued, so the state machine runs the enqueued state handler, and the latter adds it to a job queue watched by worker pool.
So, QueuePollInterval applies only to Enqueued state, but have effect on Scheduled jobs either.
I intend to create a custom store connecting hangfire to a Database-as-a-Service database which will bill me on a per request basis, so I’m wondering how chatty hangfire is for CRON tasks. Is there polling in this case too ?