Skip to content

imranmomin/Hangfire.AzureCosmosDb

Repository files navigation

Hangfire.AzureCosmosDB

Official Site Latest version Downloads Build status

This repo will add a Microsoft Azure Cosmos DB storage support to Hangfire - fire-and-forget, delayed and recurring tasks runner for .NET. Scalable and reliable background job runner. Supports multiple servers, CPU and I/O intensive, long-running and short-running jobs.

Installation

Hangfire.AzureCosmosDB is available on NuGet.

Package Manager

PM> Install-Package Hangfire.AzureCosmosDB

.NET CLI

> dotnet add package Hangfire.AzureCosmosDB

PackageReference

<PackageReference Include="Hangfire.AzureCosmosDB" Version="0.0.0" />

Usage

Use one the following ways to initialize CosmosDbStorage

GlobalConfiguration.Configuration.UseAzureCosmosDbStorage("<url>", "<authSecret>", "<databaseName>", "<collectionName>");

------------------------------------------------ 

Hangfire.Azure.CosmosDbStorage storage = Hangfire.Azure.CosmosDbStorage.Create("<url>", "<authSecret>", "<databaseName>", "<collectionName>");
GlobalConfiguration.Configuration.UseStorage(storage);
// customize any options
Hangfire.Azure.CosmosDbStorageOptions options = new Hangfire.Azure.CosmosDbStorageOptions
{
    ExpirationCheckInterval = TimeSpan.FromMinutes(2),
    CountersAggregateInterval = TimeSpan.FromMinutes(2),
    QueuePollInterval = TimeSpan.FromSeconds(15)
};

GlobalConfiguration.Configuration.UseAzureCosmosDbStorage("<url>", "<authSecret>", "<databaseName>", "<collectionName>", cosmoClientOptions, options);

------------------------------------------------ 

Hangfire.Azure.CosmosDbStorage storage = Hangfire.Azure.CosmosDbStorage.Create("<url>", "<authSecret>", "<databaseName>", "<collectionName>", cosmoClientOptions, options);
GlobalConfiguration.Configuration.UseStorage(storage);

Recommendations

  • Keep separate database/collection for the hangfire. (Now you can enable free tier on Azure)

SDK Support

This package only supports the latest Microsoft.Azure.Cosmos SDK v3

Questions? Problems?

Open-source project are developing more smoothly, when all discussions are held in public.

If you have any questions or problems related to Hangfire.AzureCosmosDB itself or this storage implementation or want to discuss new features, please create under issues and assign the correct label for discussion.

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