Use multiple instance of hangfire with single database

Viewed 4901

Has anyone used multiple instances of Hangfire (in different applications) with same SQL DB for configuration. So instead of creating new SQL DB for each hangfire instance i would like to share same DB with multiple instances.

As per the hangfire documentation here it is supported since v1.5 However forum discussion here and here shows we still have issues running multiple instances with same db

Update 1
So based on suggestions and documentation i configired hangfire to use queue

   public void Configure(IApplicationBuilder app, IHostingEnvironment env, 
   ILoggerFactory loggerFactory)
   {
        app.UseHangfireServer(new BackgroundJobServerOptions()
        {
            Queues = new string[] { "instance1" }
        });
   }

Method to invoke

[Queue("instance1")]
public async Task Start(int requestID)
{

}

This is how i Enqueue job

 _backGroundJobClient.Enqueue<IPrepareService>(x => x.Start(request.ID));

however when i check [JobQueue] table the new job has queue name default and because of that hangfire will never pickup that job because it picks up jobs for queues.

I think is a bug

Update 2

Found one more thing. I am using instance of IBackgroundJobClient. The instance is automatically get injected by .Net Core's inbuilt container.

So if i use instance to enqueue the job then hangfire creates new job with default queue name

 _backGroundJobClient.Enqueue<IPrepareService>(x => x.Start(request.ID));

However if i use static method, then hangfire creates new job with configured queue name instance1

  BackgroundJob.Enqueue<IPrepareService>(x => x.Start(prepareRequest.ID));

How do i configure hangfire in .Net Core so the instance of IBackgroundJobClient will use configure queue name ?

1 Answers
Related