layout | title | product_name | sub_active | redirect_from |
---|---|---|---|---|
products |
Hangfire Overview |
Hangfire |
overview |
/core/ |
Hangfire is a set of open-source libraries that help you to create, process and manage your background jobs, i.e. operations you don't want to put in your request processing pipeline:
- mass notifications/newsletter;
- batch import from xml, csv, json;
- creation of archives;
- firing off web hooks;
- deleting users;
- building different graphs;
- image/video processing;
- purge temporary files;
- recurring automated reports;
- database maintenance.
Hangfire supports all kind of background tasks – short-running and long-running, CPU intensive and I/O intensive, one shot and recurrent. You don't need to reinvent the wheel – it is ready to use.
These jobs are being executed only once and almost immediately after they fired.
BackgroundJob.Enqueue( () => Console.WriteLine("Fire-and-forget!"));
Recurring jobs fired many times on the specified CRON schedule.
RecurringJob.AddOrUpdate( () => Console.WriteLine("Recurring!"), Cron.Daily);
Background jobs is very important part of an application and Hangfire ensures that any job is being performed at least once. To persist background job information between application restarts, all the information is being saved in your favorite persistent storage. Currently the following storages are supported:
All product names, logos, and brands are property of their respective owners, and are in no way associated or affiliated with Hangfire.
Storage subsystem is abstracted enough to support RDBMS and NoSQL solutions. If your favorite database system is not supported yet, you can implement it. It is cheaper than implementing a background job system from scratch.
If your background job face with a problem during its execution, it will be retried automatically after some delay. Hangfire successfully deals with the following problems:
- Exceptions
- Application shutdowns
- Unexpected process terminations
You are also able to retry any background job manually through the programming code or the Dashboard UI:
var succeeded = BackgroundJob.Requeue(jobId); {% endhighlight %}
You are not required to make any architecture decisions to start using Hangfire. You can begin with simple setup, where background processing is being implemented on the web application side.
Later, when you face with performance problems, you can separate the processing among different processes or servers – Hangfire uses distributed locks to handle synchronization issues.
<!-- Tab panes -->
<div class="tab-content tab-content-center text-center">
<div role="tabpanel" class="tab-pane active" id="process">
<img src="/img/process.png" alt="Single Process">
</div>
<div role="tabpanel" class="tab-pane" id="garden">
<img src="/img/garden.png" alt="Web Garden">
</div>
<div role="tabpanel" class="tab-pane" id="farm">
<img src="/img/farm.png" alt="Web Farm">
</div>
<div role="tabpanel" class="tab-pane" id="service">
<img src="/img/service.png" alt="Separate Service">
</div>
<div role="tabpanel" class="tab-pane" id="server">
<img src="/img/server.png" alt="Separate Server">
</div>
</div>
Hangfire is shipped with an awesome tool – Web Monitoring UI. It is implemented as an OWIN extensions and though can be hosted inside any application – ASP.NET, Console or Windows Service. Monitoring UI allows you to see and control any aspect of background job processing, including statistics, exceptions and background job history.
Just look at the screenshots below, and you'll love it!