Fire-and-forget method invocation has never been simpler. As you already know from the Quick start guide, you only need to pass a lambda expression with the corresponding method and its arguments:
BackgroundJob.Enqueue(() => Console.WriteLine("Hello, world!"));
Enqueue method does not call the target method immediately, it runs the following steps instead:
After these steps were performed, the
BackgroundJob.Enqueue method immediately returns to a caller. Another Hangfire component, called Hangfire Server, checks the persistent storage for enqueued background jobs and performs them in a reliable way.
Enqueued jobs are handled by a dedicated pool of worker threads. The following process is invoked by each worker:
So, the job is removed only after processing succeeds. Even if a process was terminated during the performance, Hangfire will perform compensation logic to guarantee the processing of each job.
Each storage has its own implementation for each of these steps and compensation logic mechanisms:
BRPOPLPUSHcommand, so jobs are fetched immediately, as with MSMQ. But in case of process termination, they are re-enqueued only after timeout expiration (30 minutes by default).