Is there an in memory job storage package for Hangfire?

Lost_In_Library picture Lost_In_Library · Apr 4, 2017 · Viewed 17k times · Source

I have a console application to test HangFire. Here is the code:

using System;
using Hangfire;

namespace MyScheduler.ConsoleApp
{
    internal static class Program
    {
        internal static void Main(string[] args)
        {
            MyMethod();

            Console.WriteLine("[Finished]");
            Console.ReadKey();
        }

        private static void MyMethod()
        {
            RecurringJob.AddOrUpdate(() => Console.Write("Easy!"), Cron.Minutely);
        }
    }
}

But it throws an exception on runtime:

Additional information: JobStorage.Current property value has not been initialized. You must set it before using Hangfire Client or Server API.

So I need a job storage to run this. But all examples in SQL storage etc. Is there any way to run this example with some kind of memory storage?

JobStorage.Current = new SqlServerStorage("ConnectionStringName", options);  
// to  
JobStorage.Current = new MemoryDbStorage(string.Empty, options);  

Answer

Yogi picture Yogi · Apr 4, 2017

You can use Hangfire.MemoryStorage for this.

Simply add this nuget package.

And then you can use it like -

GlobalConfiguration.Configuration.UseMemoryStorage();