Are you tired of waiting for a response? 

Use Hangfire!

Are you tired of waiting for a response – use Hangfire

At Vertica we spend quite a great deal of our time at the office implementing integrations to different types of external systems like PIM, ERP and Elastic Cloud. This usually requires our systems to be able to perform background processing, there are often 2 types of background processing required in our systems.


Start an asynchronous background task during the execution of a http web request

To prevent a user from having to wait for a time consuming task to complete in a web request the system needs to be able to start asynchronous background tasks and return the response to the user without waiting for the task to complete. Some examples when this kind of background processing is required are:

  • Processing a completed order
  • Send transactional e-mails


Start scheduled background tasks

In our solutions we usually exchange data with different types of systems and it is quite common that this is done on a schedules basis. Some examples when this kind of background processing is required are:

  • Importing product information from an ERP or PIM system
  • Exporting transactions to an ERP system
  • Indexing product catalogs
  • Create xml sitemaps for Google
  • Data clean-up tasks

 

Hangfire – A background processing engine for .NET

The component we currently are using at Vertica to be able to execute background tasks in our applications is called Hangfire. The projects web page is found here.

Hangfire is an open-source framework that helps you to create, process and manage your background jobs, i.e. operations you don't want to put in your request processing pipeline and it is available as an NuGet package for both the .NET Standard and Core framework.

The module consists of three main components: client, storage and server.

 

Hangfire can both be hosted in your web application or in a console application. In an Azure context we often use continuous Azure WebJob:s to run the Hangfire background worker in a console application. This approach separates the background processing from the web application and heavy background processing does not affect the wp3 process. Another approach is to host the WebJob in its own app service to separate the background processing from the web application even more.