Question about how jobs are executed

recurring
Tags: #<Tag:0x00007f49a0cbb308>

#1

Ok, so I have Hangfire running, along with the dashboard. When I look at the dashboard, I see I have two “servers”. Seems ok so far. Im wondering about a scenario where a job takes longer than normal and bumps into the schedule of its own or another job.

eg. Job-1 is taking longer than normal and is defined with a recurring schedule, lets say every 30 min. Ok, Job-1 has been running for 29 min … if its not done at the 30 min mark, will this same job be started and possibly put on the 2nd server worker?


#2

A job will be enqueued from the schedule without any regard to previous jobs running. So yes, you can have 2 of RecurringJob1 executing at the same time.


#3

How can I ensure this does not happen? I dont want to have another of the same job started if there is another still running. With a .net core web app, I gathered from the docs that setting the worker count to 1 would ensure that?
app.UseHangfireServer(new BackgroundJobServerOptions { WorkerCount = 1 });


#4

That would work. If you have other jobs that you don’t want the wait for this one, then you probably want to handle the job with a check in your own database if it’s running …