Hangfire

What is Hangfire?

The Hangfire is an open-source .net package. It allows you to run scheduled jobs with limited amount of administrative cost. Just like Windows Scheduler, Windows Service deployment is not easy, but with the help of Hangfire you can run different types of background jobs such as one time jobs (aka fire and forget), recurring jobs.

Hangfire also provides you a dashboard that represent various information such as job status report, graph, exception details etc…

How to use Hangfire?

There are many good articles on how to use and setup Hangfire. However, I suggest you to read this book from the Author: https://media.readthedocs.org/pdf/hangfire/latest/hangfire.pdf

Extra Bit

Since I have successfully implemented the same in my job, I would like to preserve my learning in this blog, along with my good looking sketch notes.

Take Away:

  • If you are planning to use for an Enterprise Platform, I suggest you to buy Hangfire Pro version, which comes with dedicated support, performance counter and other improved benefits such as Redis database support.
  • Hangfire logs a lot. Hence, I suggest you to either implement your own LogProvider for the Hangfire or if you are using a log framework such as NUnit then don’t forget to set a filter on severity level.
  • If you are using Hangfire with the Microsoft SQL Server then you might want to assess the default polling time, which is every 15 seconds.
  • By default Hangfire dashboard is accessible for localhost. You can enable or disable for production, but don’t forget to set some sort of an Authentication mechanism. The good thing is, if you don’t want Windows or Basic Authentication, you can provide your own implementation.
  • If you can afford to have a separate Hangfire database, then please create a dedicated database for your Hangfire instance. It will give you an opportunity to scale, and share the same Hangfire instance with many other projects. Otherwise, you can stick to a separate database schema.
  • Hangfire is awesome because you don’t need any server access like in the case of Windows Scheduler or Windows Services.

Like I said before you can use this sketch note for your reference.

Namaste!