Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Hangfire - startup implementing #9216


User avatar
0
deltavision created

Hi,

using: Core, MVC, jQuery project - v7.2.2

We wish to implement Hangfire in a project - but have som questions :-)

Need a background job running for each tenant - on a scheduled basis. (RecurringJob.AddOrUpdate) Should always be running - that is when the web site starts, the job should be "created" and start running. So no "manual" trigger to start job.

In the ....Web.Core project

  • Webconst - HangfireDashboardEnabled set to true
  • In this project should I uncomment "Configureation.BackgroundJobs.UseHangfire() in the ... WebCoreModule?

In the ...Web.Host project

  • Startup.cs - no changes made - it is checking the WebConst HangfireDashboardEnabled - OK?

**In the ...Web.Mvc project **

  • Startup.cs - no changes made - it is checking the WebConst HangfireDashboardEnabled - OK?

Defining / starting the Hangfire job From searching I can see that often jobs are created / started in the PostInitialize - eg. in ...WebMvcModule of the ...Web.Mvc project Is this the correct approach?

Or should we make a new controller? and then how do we trigger the job?

Should we create a class like below - based on BackgroundJob - and make an Execute method?

public class TestStatusService : BackgroundJob<int>, ITransientDependency

hoping for some "best practice" input :-)


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

    Hi ismcagdas

    yes we did :-)

    but do you have any best-practice for creating the jobs - where to initialize them (PostInitialize or...) and if we should use class based on BackgroundJob<>

  • User Avatar
    0
    musa.demir created

    You can use background job as you normally would. https://aspnetboilerplate.com/Pages/Documents/Background-Jobs-And-Workers

    For example you can check ImportUsersToExcelJob

  • User Avatar
    0
    BobIngham created
  • User Avatar
    0
    deltavision created

    @bobingham,

    thank you - works perfectly :-)

  • User Avatar
    0
    BobIngham created

    Glad to be of help.