Hangfire.Mongo
1.11.2
dotnet add package Hangfire.Mongo --version 1.11.2
NuGet\Install-Package Hangfire.Mongo -Version 1.11.2
<PackageReference Include="Hangfire.Mongo" Version="1.11.2" />
paket add Hangfire.Mongo --version 1.11.2
#r "nuget: Hangfire.Mongo, 1.11.2"
// Install Hangfire.Mongo as a Cake Addin #addin nuget:?package=Hangfire.Mongo&version=1.11.2 // Install Hangfire.Mongo as a Cake Tool #tool nuget:?package=Hangfire.Mongo&version=1.11.2
Hangfire.Mongo
MongoDB support for Hangfire library. By using this library you can store all jobs information in MongoDB.
Installation
To install Hangfire MongoDB Storage, run the following command in the Nuget Package Manager Console:
PM> Install-Package Hangfire.Mongo
Usage ASP.NET Core
public void ConfigureServices(IServiceCollection services)
{
var mongoUrlBuilder = new MongoUrlBuilder("mongodb://localhost/jobs");
var mongoClient = new MongoClient(mongoUrlBuilder.ToMongoUrl());
// Add Hangfire services. Hangfire.AspNetCore nuget required
services.AddHangfire(configuration => configuration
.SetDataCompatibilityLevel(CompatibilityLevel.Version_180)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseMongoStorage(mongoClient, mongoUrlBuilder.DatabaseName, new MongoStorageOptions
{
MigrationOptions = new MongoMigrationOptions
{
MigrationStrategy = new MigrateMongoMigrationStrategy(),
BackupStrategy = new CollectionMongoBackupStrategy()
},
Prefix = "hangfire.mongo",
CheckConnection = true
})
);
// Add the processing server as IHostedService
services.AddHangfireServer(serverOptions =>
{
serverOptions.ServerName = "Hangfire.Mongo server 1";
});
// Add framework services.
}
Usage ASP.NET
var options = new MongoStorageOptions
{
MigrationOptions = new MongoMigrationOptions
{
MigrationStrategy = new DropMongoMigrationStrategy(),
BackupStrategy = new NoneMongoBackupStrategy()
}
};
GlobalConfiguration.Configuration.UseMongoStorage("mongodb://localhost/jobs", options);
app.UseHangfireServer();
app.UseHangfireDashboard();
Usage Console
var options = new MongoStorageOptions
{
MigrationOptions = new MongoMigrationOptions
{
MigrationStrategy = new DropMongoMigrationStrategy(),
BackupStrategy = new NoneMongoBackupStrategy()
}
};
var mongoStorage = new MongoStorage(
MongoClientSettings.FromConnectionString("mongodb://localhost"),
"jobs", // database name
options);
using(new BackgroundJobServer(mongoStorage))
{
...
}
Custom collections prefix
To use custom prefix for collections names specify it on Hangfire setup:
public void Configuration(IAppBuilder app)
{
GlobalConfiguration.Configuration.UseMongoStorage("mongodb://localhost/ApplicationDatabase",
new MongoStorageOptions { Prefix = "custom" } );
app.UseHangfireServer();
app.UseHangfireDashboard();
}
Configuration Overrides
CheckQueuedJobsStrategy
(default:Watch
)Watch
uses change streams to watch for enqueued jobs. Will still poll using 'QueuePollInterval'.Poll
will poll periodically using 'QueuePollInterval', recommended for large installments.TailNotificationsCollection
uses a capped, tailable collection to notify nodes of enqueued jobs. Will still poll using 'QueuePollInterval'. Works with single node MongoDB instances.
Naming Convention
Hangfire.Mongo will ignore any naming conventions configured by your application. E.g. if your application use camel casing like this:
var camelCaseConventionPack = new ConventionPack { new CamelCaseElementNameConvention() };
ConventionRegistry.Register("CamelCase", camelCaseConventionPack, type => true);
it will be ignored by Hangfire.Mongo and Pascal Case will be used instead. Of cause only for Hangfire specific collections.
Migration
We sometimes introduce breaking changes in the schema. For this reason we have introduced migration. Three migration strategies exists.
Throw
This is the default migration strategy. It will throw an InvalidOperationException never letting you get up and running if there is a schema version mismatch. So it forces you to decide what migration strategy is best for you and at the same time keeps your data safe.
Drop
This will simply just drop your existing Hangfire.Mongo database and update the schema version. No fuzz and ready to start from scratch. It is the perfect strategy if you e.g. enque all your jobs at startup.
Migrate
This will migrate your database from one schema version to the next until the required schema version is reached. Chances are that not all data can be migrated, why some loss of data might occur. Please use with caution and thougoughly test before deploying to production. We are not responsible for data loss.
NOTE: Only forward migration is supported. If you need to revert to a previous schema version, you need to manually drop or restore the previous database.
public void Configuration(IAppBuilder app)
{
var migrationOptions = new MongoMigrationOptions
{
MigrationStrategy = new MigrateMongoMigrationStrategy(),
BackupStrategy = new CollectionMongoBackupStrategy()
};
var storageOptions = new MongoStorageOptions
{
// ...
MigrationOptions = migrationOptions
};
GlobalConfiguration.Configuration.UseMongoStorage("<connection string with database name>", storageOptions);
app.UseHangfireServer();
app.UseHangfireDashboard();
}
NOTE: By default the parameter InvisibilityTimeout
of the MongoStorageOptions
is configured with the value null
, making the job to stay in status 'processing' in case of an error in the application. To solve this issue, set the value to 30 minutes like in the SqlServerStorageOptions.
public void Configuration(IAppBuilder app)
{
var migrationOptions = new MongoMigrationOptions
{
MigrationStrategy = new MigrateMongoMigrationStrategy(),
BackupStrategy = new CollectionMongoBackupStrategy()
};
var storageOptions = new MongoStorageOptions
{
// ...
MigrationOptions = migrationOptions,
InvisibilityTimeout = TimeSpan.FromMinutes(30)
};
GlobalConfiguration.Configuration.UseMongoStorage("<connection string with database name>", storageOptions);
app.UseHangfireServer();
app.UseHangfireDashboard();
}
Migration Backup
By default no backup is made before attempting to migrate. You can backup Hangfire collections by "cloning" each collection to the same database. Alternatively you can just write your own, by inheriting MongoBackupStrategy and use that implementation.
NOTE: This software is made by humans in our sparetime - we do our best but will not be held responsible for any data loss.
Contributors
- Sergey Zwezdin (@sergeyzwezdin)
- Martin Løbger (@marloe)
- Jonas Gottschau (@gottscj)
License
Hangfire.Mongo is released under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
.NET Framework | net472 is compatible. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.7.2
- Hangfire.Core (>= 1.8.16)
- MongoDB.Driver (>= 3.0.0)
- Newtonsoft.Json (>= 13.0.3)
-
.NETStandard 2.1
- Hangfire.Core (>= 1.8.16)
- MongoDB.Driver (>= 3.0.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages (19)
Showing the top 5 NuGet packages that depend on Hangfire.Mongo:
Package | Downloads |
---|---|
DiegoRangel.DotNet.Framework.CQRS.Infra.CrossCutting.Hangfire
A common library for implementing CQRS based CrossCutting Hangfire layer. |
|
EaCloud.Hangfire
EaCloud Hangfire 后台任务组件,封装基于 Hangfire 后台任务的服务端实现。 |
|
Conexus.Common
Package Description |
|
MicroCloud.Hangfire
MicroCloud Hangfire 后台任务组件,封装基于 Hangfire 后台任务的服务端实现。 |
|
nguyendk.DotnetExtensions.NET
Package Description |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Hangfire.Mongo:
Repository | Stars |
---|---|
gnsilence/HangfireHttpJob
hangfire的拓展程序,在原作者基础上增加了一些功能,调用api的方式来执行定时任务
|
Version | Downloads | Last updated |
---|---|---|
1.11.2 | 11,243 | 11/27/2024 |
1.11.1 | 10,578 | 11/18/2024 |
1.11.0 | 16,948 | 10/30/2024 |
1.10.9 | 63,609 | 10/3/2024 |
1.10.8 | 109,313 | 8/7/2024 |
1.10.7 | 119,122 | 6/17/2024 |
1.10.6 | 115,610 | 4/24/2024 |
1.10.5 | 29,669 | 4/9/2024 |
1.10.4 | 105,999 | 2/26/2024 |
1.10.3 | 42,512 | 2/11/2024 |
1.10.2 | 3,254 | 2/8/2024 |
1.10.1 | 1,416 | 2/7/2024 |
1.10.0 | 2,291 | 2/7/2024 |
1.9.16 | 61,125 | 1/4/2024 |
1.9.15 | 75,769 | 11/28/2023 |
1.9.14 | 29,181 | 11/12/2023 |
1.9.13 | 702 | 11/10/2023 |
1.9.12 | 38,941 | 10/28/2023 |
1.9.11 | 35,844 | 10/14/2023 |
1.9.10 | 52,559 | 9/21/2023 |
1.9.9 | 33,364 | 9/11/2023 |
1.9.8 | 49,017 | 8/14/2023 |
1.9.7 | 171,864 | 7/18/2023 |
1.9.6 | 49,433 | 6/18/2023 |
1.9.5 | 152,923 | 5/18/2023 |
1.9.4 | 3,720 | 5/15/2023 |
1.9.3 | 156,208 | 3/31/2023 |
1.9.2 | 185,849 | 2/2/2023 |
1.9.1 | 219,448 | 12/19/2022 |
1.9.0 | 28,972 | 12/10/2022 |
1.7.3 | 456,802 | 8/24/2022 |
1.7.2 | 144,241 | 6/13/2022 |
1.7.1 | 54,192 | 6/8/2022 |
1.7.0 | 258,369 | 3/19/2022 |
0.7.28 | 204,443 | 1/2/2022 |
0.7.27 | 142,467 | 11/3/2021 |
0.7.25 | 85,035 | 9/20/2021 |
0.7.24 | 115,852 | 8/8/2021 |
0.7.22 | 285,305 | 5/2/2021 |
0.7.20 | 96,484 | 3/25/2021 |
0.7.19 | 78,834 | 2/10/2021 |
0.7.17 | 155,832 | 11/20/2020 |
0.7.12 | 156,099 | 8/12/2020 |
0.7.11 | 198,743 | 6/7/2020 |
0.6.7 | 198,410 | 3/19/2020 |
0.6.6 | 433,431 | 12/11/2019 |
0.6.5 | 87,044 | 10/21/2019 |
0.6.4 | 18,741 | 9/26/2019 |
0.6.3 | 28,168 | 8/14/2019 |
0.6.2 | 18,908 | 7/28/2019 |
0.6.1 | 39,399 | 6/16/2019 |
0.6.0 | 43,265 | 4/23/2019 |
0.5.15 | 147,876 | 1/3/2019 |
0.5.14 | 2,013 | 1/1/2019 |
0.5.13 | 13,844 | 12/13/2018 |
0.5.12 | 46,942 | 10/28/2018 |
0.5.11 | 85,290 | 9/5/2018 |
0.5.10 | 40,190 | 5/27/2018 |
0.5.9 | 55,956 | 2/20/2018 |
0.5.8 | 2,267 | 2/20/2018 |
0.5.7 | 86,872 | 11/20/2017 |
0.5.6 | 1,841 | 11/20/2017 |
0.5.5 | 12,708 | 10/14/2017 |
0.5.4 | 10,614 | 9/22/2017 |
0.5.3 | 3,056 | 9/21/2017 |
0.5.2 | 30,175 | 9/1/2017 |
0.5.1 | 2,413 | 8/30/2017 |
0.5.0 | 3,836 | 8/17/2017 |
0.4.1 | 14,549 | 6/22/2017 |
0.4.0 | 5,283 | 6/19/2017 |
0.3.2 | 59,738 | 12/10/2016 |
0.3.1 | 2,187 | 11/30/2016 |
0.3.0 | 2,220 | 11/29/2016 |
0.2.8 | 8,425 | 9/26/2016 |
0.2.6 | 217,443 | 5/29/2016 |
0.2.5 | 5,179 | 3/5/2016 |
0.2.4 | 2,536 | 2/15/2016 |
0.2.3 | 2,858 | 12/6/2015 |
0.2.2 | 5,857 | 7/12/2015 |
0.2.1 | 3,157 | 12/13/2014 |
0.2.0 | 2,425 | 12/7/2014 |
1.11.2
- Minor tweaks to migration
- Dont delete migration lock on shutdown
- Update to Hangfire.Core 1.8.16
- TargetFrameworks is set to net472 and netstandard2.1