Is there a memory job storage for Hangfire?

I have a console application for testing 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 at runtime:

Additional Information: The value of the JobStorage.Current property was not initialized. You must install it before using the Hangfire Client or Server API.

To do this, I need a job repository. But all the examples are in SQL repository, etc. Is there any way to run this example with some kind of memory store?

 JobStorage.Current = new SqlServerStorage("ConnectionStringName", options); // to JobStorage.Current = new MemoryDbStorage(string.Empty, options); 
+5
source share
3 answers

You can use Hangfire.MemoryStorage for this.

Just add this nuget package .

And then you can use it like -

 GlobalConfiguration.Configuration.UseMemoryStorage(); 
+19
source

For NET Core (web application):

Just to make it very obvious, because it was not obvious to me.

Install the following nuget packages:

  • Hangfire AspNet Core (v1.6.17 atow)
  • Hangfire.MemoryStorage.Core (v1.4.0 atow)

In Startup.cs:

  public void ConfigureServices(IServiceCollection services) { // other registered services ... services.AddHangfire(c => c.UseMemoryStorage()); } public void Configure(IApplicationBuilder app, IHostingEnvironment env) { // other pipeline configuration ... app.UseHangfireServer(); app.UseMvc(); } 

Nothing less than the above, and my queued method didn't work.

+2
source

As Yogi said, you can use Hangfire.MemoryStorage or Hangfire.MemoryStorage.Core (for .Net Core).

This answer is missing the full code (for .Net Core) that needs to be placed inside ConfigureServices (..):

 var inMemory = GlobalConfiguration.Configuration.UseMemoryStorage(); services.AddHangfire(x => x.UseStorage(inMemory)); 
+1
source

Source: https://habr.com/ru/post/1266305/


All Articles