Hangfire.Realm 1.0.2

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

There is a newer version of this package available.
See the version list below for details.
Install-Package Hangfire.Realm -Version 1.0.2
dotnet add package Hangfire.Realm --version 1.0.2
<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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Hangfire.Realm, 1.0.2"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. 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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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.

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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.5 149 8/4/2021
1.0.4 2,291 7/10/2020
1.0.4-RC1 418 7/10/2020
1.0.4-prerelease7 370 7/10/2020
1.0.4-prerelease6 384 7/9/2020
1.0.4-prerelease5 358 7/9/2020
1.0.4-prerelease4 385 7/9/2020
1.0.4-prerelease3 367 5/14/2020
1.0.4-prerelease2 362 5/14/2020
1.0.4-prerelease 375 5/14/2020
1.0.3 778 11/27/2019
1.0.2 414 11/25/2019
1.0.1 520 11/20/2019
1.0.0 511 11/8/2019
Show less