An easy way to perform background processing in your .NET and .NET Core applications
C# PLpgSQL Other
Pull request Compare This branch is even with aidmsu:master.
Permalink
Failed to load latest commit information.
.nuget Update NuGet client executable to 3.5 RTM Nov 2, 2016
content Add sample ASP.NET Core Startup.cs Jul 15, 2016
nuspecs Add missing attributions for 1.6.5 release notes Nov 25, 2016
samples Make MvcSample project compatible with VS 2017 Nov 29, 2016
src Fix typo "Nexts jobs" should be "Next jobs" in dashboard (#754) Dec 2, 2016
tests Throw NotSupported when job contains delegate or expression Dec 2, 2016
.editorconfig Replace tabs with spaces in psake-project.ps1 Mar 19, 2015
.gitattributes Enable autoconversion of files line endings (#722) Nov 14, 2016
.gitignore Update gitignore and remove .lock.json files (#610) Jul 13, 2016
.travis.yml Configure AppVeyor and Travis CI build notifications (#720) Nov 8, 2016
CONTRIBUTING.md Update for security issues Oct 14, 2016
COPYING LGPL v3 license text Nov 10, 2013
COPYING.LESSER LGPL v3 license text Nov 10, 2013
EULA Create EULA Dec 24, 2014
Hangfire.Mono.sln Remove Hangfire.SqlServer.RabbitMQ from Hangfire.Mono Jan 21, 2016
Hangfire.sln Add support for .NET Framework 4.5.1 in Hangfire.AspNetCore Jul 12, 2016
Hangfire.sln.DotSettings Fixes occasional crashes of Recurring Jobs page (#730) Nov 16, 2016
LICENSE.md Update copyright year Feb 19, 2016
README.md Change coverage batch to use Codecov Nov 25, 2016
appveyor.yml Configure AppVeyor and Travis CI build notifications (#720) Nov 8, 2016
build.bat Lower the verbosity of NuGet install command Jul 1, 2016
codecov.yml Change Codecov comment layout to include total coverage Nov 2, 2016
global.json Disable tests that cover TypeConverter in netstandard build Jul 18, 2016
psake-project.ps1 Change build target for CI builds Sep 24, 2016

README.md

Hangfire

Official Site Latest version License LGPLv3 codecov Coverity Scan Build Status

Build Status

  master dev
Windows Windows Build Status Windows Build Status
Linux / OS X Travis CI Build Status Linux and OS X Build Status

Overview

Incredibly easy way to perform fire-and-forget, delayed and recurring jobs inside ASP.NET applications. CPU and I/O intensive, long-running and short-running jobs are supported. No Windows Service / Task Scheduler required. Backed by Redis, SQL Server, SQL Azure and MSMQ.

Hangfire provides a unified programming model to handle background tasks in a reliable way and run them on shared hosting, dedicated hosting or in cloud. You can start with a simple setup and grow computational power for background jobs with time for these scenarios:

  • mass notifications/newsletters
  • batch import from xml, csv or json
  • creation of archives
  • firing off web hooks
  • deleting users
  • building different graphs
  • image/video processing
  • purging temporary files
  • recurring automated reports
  • database maintenance
  • …and so on

Hangfire is a .NET Framework alternative to Resque, Sidekiq, delayed_job, Celery.

Hangfire Dashboard

Installation

Hangfire is available as a NuGet package. You can install it using the NuGet Package Console window:

PM> Install-Package Hangfire

After installation, update your existing OWIN Startup file with the following lines of code. If you do not have this class in your project or don't know what is it, please read the Quick start guide to learn about how to install Hangfire.

public void Configuration(IAppBuilder app)
{
    GlobalConfiguration.Configuration.UseSqlServerStorage("<connection string or its name>");
    
    app.UseHangfireServer();
    app.UseHangfireDashboard();
}

Usage

This is an incomplete list of features; to see all of them, check the official site and the documentation.

Fire-and-forget tasks

Dedicated worker pool threads execute queued background jobs as soon as possible, shortening your request's processing time.

BackgroundJob.Enqueue(() => Console.WriteLine("Simple!"));

Delayed tasks

Scheduled background jobs are executed only after a given amount of time.

BackgroundJob.Schedule(() => Console.WriteLine("Reliable!"), TimeSpan.FromDays(7));

Recurring tasks

Recurring jobs have never been simpler; just call the following method to perform any kind of recurring task using the CRON expressions.

RecurringJob.AddOrUpdate(() => Console.WriteLine("Transparent!"), Cron.Daily);

Continuations

Continuations allow you to define complex workflows by chaining multiple background jobs together.

var id = BackgroundJob.Enqueue(() => Console.WriteLine("Hello, "));
BackgroundJob.ContinueWith(id, () => Console.WriteLine("world!"));

Process background tasks inside a web application…

You can process background tasks in any OWIN-compatible application framework, including ASP.NET MVC, ASP.NET Web API, FubuMvc, Nancy, etc. Forget about AppDomain unloads, Web Garden & Web Farm issues – Hangfire is reliable for web applications from scratch, even on shared hosting.

app.UseHangfireServer();

… or anywhere else

In console applications, Windows Service, Azure Worker Role, etc.

using (new BackgroundJobServer())
{
    Console.WriteLine("Hangfire Server started. Press ENTER to exit...");
    Console.ReadLine();
}

Questions? Problems?

Open-source projects develop more smoothly when discussions are public.

If you have any questions, problems related to Hangfire usage or if you want to discuss new features, please visit the discussion forum. You can sign in there using your existing Google or GitHub account, so it's very simple to start using it.

If you've discovered a bug, please report it to the Hangfire GitHub Issues. Detailed reports with stack traces, actual and expected behavours are welcome.

Related Projects

Please see the Extensions page on the official site.

Building the sources

To build a solution and get assembly files, just run the following command. All build artifacts, including *.pdb files, will be placed into the build folder. Before proposing a pull request, please use this command to ensure everything is ok. Btw, you can execute this command from the Package Manager Console window.

build

To build NuGet packages as well as an archive file, use the pack command as shown below. You can find the result files in the build folder.

build pack

To see the full list of avalable commands, pass the -docs switch:

build -docs

Hangfire uses psake build automation tool. All psake tasks and functions defined in psake-build.ps1 (for this project) and psake-common.ps1 (for other Hangfire projects) files. Thanks to the psake project, they are very simple to use and modify!

License

Copyright © 2013-2016 Sergey Odinokov.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Legal

By submitting a Pull Request, you disavow any rights or claims to any changes submitted to the Hangfire project and assign the copyright of those changes to Sergey Odinokov.

If you cannot or do not want to reassign those rights (your employment contract for your employer may not allow this), you should not submit a PR. Open an issue and someone else can do the work.

This is a legal way of saying "If you submit a PR to us, that code becomes ours". 99.9% of the time that's what you intend anyways; we hope it doesn't scare you away from contributing.