1 week ago / 101 views / 3 minutes read
In today's world, software is more than just user interfaces, forms, and data storage. To develop software that aims to enhance, accelerate, and improve an organization's or business's performance, user interaction alone isn't enough. There are tasks and operations with a different nature from direct user interaction, or that require heavier processing than simple CRUD operations. Examples of these include monitoring thousands of database records to perform specific operations, generating complex reports, or executing scheduled commands even when no user is interacting with the system. This article introduces the Hangfire framework for implementing Background Jobs on the .NET platform.
Depending on the needs, background operations can be categorized as follows:
Fire-and-Forget Jobs: Operations that execute only once and immediately after creation.
Delayed Jobs: These operations are executed after a specified period has passed since their creation.
Recurring Jobs: Operations that run repeatedly based on a specific schedule.
Continuation Jobs: Operations that are executed in a chain after another operation is completed.
There are several options for implementing background jobs in the .NET ecosystem, including:
Among these, Hangfire is highly popular due to its support for almost all types of background jobs and its provision of a dashboard for monitoring and managing the status and history of job executions. However, it's important to note that this framework is better suited for medium to large-scale projects. In lighter projects, using .NET's built-in features is often a more logical choice.
To store information, status, schedules, and operation logs, Hangfire requires a storage backend.
By default, Hangfire supports the following databases and storage solutions:
The choice of each option depends on the project's architecture and needs. Generally:
Summary
In this article, we've become familiar with the Hangfire framework and its features for executing background jobs on the .NET platform. For deeper learning and practical implementation, studying the official Hangfire documentation is highly recommended.