Hangfire: Server Shutdown Message?

Created on 5 Feb 2019  ·  4Comments  ·  Source: HangfireIO/Hangfire

Is there any sort of server shutdown message where the HangFire server processes its existing queue but stops accepting any new requests?

question

Most helpful comment

In version 1.7.0 there's the BackgroundJobServerOptions.StopTimeout property that sets the TimeSpan value (by default it's zero) for how long to wait for background jobs to be completed without firing CancellationToken. So shutdown pipeline looks like this (they are the log messages):

Before these signals our server is running, and we are able to pick up the new background jobs.

Server rd0003ff2199ca:13116:03c6de91 caught stopping signal...

Starting from this signal above, we don't pick any new jobs, but allow fetched ones to be completed. However, neither IJobCancellationToken nor CancellationToken are triggered.

Server rd0003ff2199ca:13116:03c6de91 caught stopped signal...

Starting from the message above we are triggering cancellation tokens to tell background jobs our server is shutting down, but give them some time to acknowledge that shutdown is triggered and safely abort themselves.

Server rd0003ff2199ca:13116:03c6de91 caught shutdown signal...

After this signal we don't wait for background jobs completion and shutting down the server and calling the RemoveServer method to un-register it.

All 4 comments

In version 1.7.0 there's the BackgroundJobServerOptions.StopTimeout property that sets the TimeSpan value (by default it's zero) for how long to wait for background jobs to be completed without firing CancellationToken. So shutdown pipeline looks like this (they are the log messages):

Before these signals our server is running, and we are able to pick up the new background jobs.

Server rd0003ff2199ca:13116:03c6de91 caught stopping signal...

Starting from this signal above, we don't pick any new jobs, but allow fetched ones to be completed. However, neither IJobCancellationToken nor CancellationToken are triggered.

Server rd0003ff2199ca:13116:03c6de91 caught stopped signal...

Starting from the message above we are triggering cancellation tokens to tell background jobs our server is shutting down, but give them some time to acknowledge that shutdown is triggered and safely abort themselves.

Server rd0003ff2199ca:13116:03c6de91 caught shutdown signal...

After this signal we don't wait for background jobs completion and shutting down the server and calling the RemoveServer method to un-register it.

Starting from this signal above, we don't pick any new jobs, but allow fetched ones to be completed.

I'm assuming that if there are no pending jobs, then the timeout occurs immediately, instead of always waiting until StopTimeout?

Yes, processing server is waiting for completion of all of its background processes, and in this case background processes will be completed immediately, leading to almost immediate completion of a processing server itself.

Why is the server shutting down? What is the recommended value for StopTimeout? I have a job running when this Server t1:6128:9a9fcab5 caught stopping signal... occurred, and the job hang. in console mode Control-C restarted it, and as a service I had to stop and restart the service.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

plmwong picture plmwong  ·  3Comments

thurfir picture thurfir  ·  4Comments

dbones picture dbones  ·  3Comments

cindro picture cindro  ·  3Comments

vikramjb picture vikramjb  ·  3Comments