Base solution for your next web application
Open Closed

Hangfire configure Queues #1549


User avatar
0
mbit created

Hi,

to use hangfire, i do: Configuration.BackgroundJobs.UseHangfire(configuration => { configuration.GlobalConfiguration.UseSqlServerStorage("Default"); });

but how can i pass a queue configuration to hangfire as described below in the hangfire documentation: <a class="postlink" href="http://docs.hangfire.io/en/latest/background-processing/configuring-queues.html">http://docs.hangfire.io/en/latest/backg ... ueues.html</a>

thank's in advance martin

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Have you tried to add

    app.UseHangfireServer(new BackgroundJobServerOptions
    {
        Queues = new[] { "critical", "default" }
    });
    

    to Startup.cs right under the like

    app.UseHangfireDashboard();
    
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    mbit created

    Hi,

    thanks a lot - it works.

    Now i ran into another problem. my main website should only start backgroundjobs and display it's progress etc. (including hangfire dashboard)

    and a second "worker" website - hosted on another server should process the jobs.

    so i tried:

    Configuration.BackgroundJobs.IsJobExecutionEnabled = false;
    

    in the website (webmodule->PreInitialize()) to prevent processing. But i seams that this setting is beeing ignored. Website is processing jobs too.

    Is there another option to prevent processing jobs by hangfire? any hint for me?

    best regards Martin

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    When you use

    app.UseHangfireServer(new BackgroundJobServerOptions
    {
        Queues = new[] { "critical", "default" }
    });
    

    regardless of the value "IsJobExecutionEnabled" hangfire server starts. <a class="postlink" href="http://docs.hangfire.io/en/latest/background-processing/processing-jobs-in-web-app.html#using-owin-extension-methods">http://docs.hangfire.io/en/latest/backg ... on-methods</a>

    So instead of setting "Configuration.BackgroundJobs.IsJobExecutionEnabled" to false, you can conditionally run the "app.UseHangfireServer" code.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)