Hangfire.Realm 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Hangfire.Realm --version 1.0.2
NuGet\Install-Package Hangfire.Realm -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Hangfire.Realm" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Hangfire.Realm --version 1.0.2
#r "nuget: Hangfire.Realm, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Hangfire.Realm as a Cake Addin
#addin nuget:?package=Hangfire.Realm&version=1.0.2

// Install Hangfire.Realm as a Cake Tool
#tool nuget:?package=Hangfire.Realm&version=1.0.2

Hangfire.Realm

Build status Nuget Nuget GitHub

This Hangfire extension adds support for using the lightweight embeddable Realm object database.

Warning: While this extension has been tested extensively in development, it has not been fully tested in production. Please use responsibly. Any developer input is appreciated.

Installation

Package Manager:

Install-Package Hangfire.Realm -Version 1.0.0

.NET CLI:

dotnet add package Hangfire.Realm --version 1.0.0

Usage

Note: If you are using Realm for persisting other data in your application and it's running on Windows make sure you use the same Realm configuration for everything. Using seperate Realm files will result in intermittant "SetEndOfFile() failed" errors. See https://github.com/realm/realm-dotnet/issues/1906

.NET Core

Please see the Hangfire.Realm.Sample.NET.Core project for a working example.

public static void Main()
{
    //The path to the Realm DB file.
    string dbPath = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                "Hangfire.Realm.Sample.NetCore.realm");

    //A standard Realm configuration.
    RealmConfiguration realmConfiguration = new RealmConfiguration(dbPath)
    {
        ShouldCompactOnLaunch = (totalBytes, usedBytes) =>
        {
            // Compact if the file is over 100MB in size and less than 50% 'used'
            var oneHundredMB = (ulong)(100 * 1024 * 1024);
            return totalBytes > oneHundredMB && (double)usedBytes / totalBytes < 0.5;
        }
    };

    //Hangfire.Realm storage options.
    RealmJobStorageOptions storageOptions = new RealmJobStorageOptions
    {
        RealmConfiguration = realmConfiguration, //Required.
        QueuePollInterval = TimeSpan.FromSeconds(1), //Optional. Defaults to TimeSpan.FromSeconds(15)
        SlidingInvisibilityTimeout = TimeSpan.FromSeconds(10), //Optional. Defaults to TimeSpan.FromMinutes(10)
        JobExpirationCheckInterval = TimeSpan.FromMinutes(1) //Optional. Defaults to TimeSpan.FromMinutes(30)
    };

    //Standard Hangfire server options.
    BackgroundJobServerOptions serverOptions = new BackgroundJobServerOptions()
    {
        WorkerCount = 10,
        Queues = new[] { "default", "critical" },
        ServerTimeout = TimeSpan.FromMinutes(10),
        HeartbeatInterval = TimeSpan.FromSeconds(30),
        ServerCheckInterval = TimeSpan.FromSeconds(10),
        SchedulePollingInterval = TimeSpan.FromSeconds(10)
    };

    //Hangfire global configuration
    GlobalConfiguration.Configuration
    .UseLogProvider(new ColouredConsoleLogProvider(Logging.LogLevel.Debug))
    .UseRealmJobStorage(storageOptions);


    using (new BackgroundJobServer(serverOptions))
    {

        //Queue a bunch of fire-and-forget jobs
        for (var i = 0; i < JobCount; i++)
        {
            var jobNumber = i + 1;
            BackgroundJob.Enqueue(() =>
            Console.WriteLine($"Fire-and-forget job {jobNumber}"));
        }

        //A scheduled job that will run 1.5 minutes after being placed in queue
        BackgroundJob.Schedule(() =>
        Console.WriteLine("A Scheduled job."),
        TimeSpan.FromMinutes(1.5));

        //A fire-and-forget continuation job that has three steps
        BackgroundJob.ContinueJobWith(
            BackgroundJob.ContinueJobWith(
            BackgroundJob.Enqueue(
                    () => Console.WriteLine($"Knock knock..")),
                    () => Console.WriteLine("Who's there?")),
                        () => Console.WriteLine("A continuation job!"));

        //A scheduled continuation job that has three steps
        BackgroundJob.ContinueJobWith(
            BackgroundJob.ContinueJobWith(
            BackgroundJob.Schedule(
                    () => Console.WriteLine($"Knock knock.."), TimeSpan.FromMinutes(2)),
                    () => Console.WriteLine("Who's there?")),
                        () => Console.WriteLine("A scheduled continuation job!"));

        //A Cron based recurring job
        RecurringJob.AddOrUpdate("recurring-job-1", () =>
        Console.WriteLine("Recurring job 1."),
        Cron.Minutely);

        //Another recurring job
        RecurringJob.AddOrUpdate("recurring-job-2", () =>
        Console.WriteLine("Recurring job 2."),
        Cron.Minutely);

        //An update to the first recurring job
        RecurringJob.AddOrUpdate("recurring-job-1", () =>
        Console.WriteLine("Recurring job 1 (edited)."),
        Cron.Minutely);

        Console.Read();
    }
}

ASP.NET Core

Please see the Hangfire.Realm.Sample.ASP.NET.Core project for a working example.

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        RealmJobStorageOptions storageOptions = new RealmJobStorageOptions
        {
            RealmConfiguration = new RealmConfiguration(
              Path.Combine(
              Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
              "Some.realm"),
            QueuePollInterval = TimeSpan.FromSeconds(1),
            SlidingInvisibilityTimeout = TimeSpan.FromSeconds(10)
        };

        services.AddHangfire(config =>
        {
            config
            .UseRealmJobStorage(storageOptions)
            .UseLogProvider(new ColouredConsoleLogProvider());
        });
        services.AddHangfireServer(options =>
        {
            options.WorkerCount = 10;
            options.Queues = new[] { "default" };
            options.ServerTimeout = TimeSpan.FromMinutes(10);
            options.HeartbeatInterval = TimeSpan.FromSeconds(30);
            options.ServerCheckInterval = TimeSpan.FromSeconds(10);
            options.SchedulePollingInterval = TimeSpan.FromSeconds(10);
        });

        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseHsts();
        }
        app.UseHangfireDashboard();
        app.UseStaticFiles();
        app.UseHttpsRedirection();
        app.UseMvc();
    }
}

The Hangfire web dashboard will be available at /hangfire.

Issues

If you have any questions or issues related to Hangfire.Realm or want to discuss new features please create a new or comment on an existing issue.

Product 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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.5 4,365 8/4/2021
1.0.4 3,324 7/10/2020
1.0.4-RC1 585 7/10/2020
1.0.4-prerelease7 576 7/10/2020
1.0.4-prerelease6 573 7/9/2020
1.0.4-prerelease5 550 7/9/2020
1.0.4-prerelease4 565 7/9/2020
1.0.4-prerelease3 552 5/14/2020
1.0.4-prerelease2 544 5/14/2020
1.0.4-prerelease 543 5/14/2020
1.0.3 1,136 11/27/2019
1.0.2 744 11/25/2019
1.0.1 902 11/20/2019
1.0.0 893 11/8/2019