Open Closed

How to prevent hangfire recurring job execution after IIS restart? #10630


0
QuickApp created

What is your product version? v10.2.0 What is your product type (Angular or MVC)? Angular What is product framework type (.net framework or .net core)? .Net Core

I have jobs running on the 1st and 11th of every month. But other than these days, they work again every time IIS is restarted.

It's annoying as these jobs will perform critical tasks like billing and tenant locking.

What would you suggest me on this?


3 Answer(s)
  • 0
    ismcagdas created
    Support Team

    Hi,

    This seems like an Hangfire problem, see https://github.com/HangfireIO/Hangfire/issues/1448.

    Could you share how do you register your job ? Maybe we can offer you a solution.

    Thanks,

  • 0
    QuickApp created

    HangfireService.cs (Web.Core) public class HangfireService { public static void InitializeJobs() { RecurringJob.AddOrUpdate<QTenantInvoiceJob>(job => job.Execute(0), $"00 00 {QCloudConsts.InvoiceCreationDay} * *"); RecurringJob.AddOrUpdate<QTenantLockJob>(job => job.Execute(0), $"00 01 {QCloudConsts.NotPaidInvoiceAndLockingDay} * *"); RecurringJob.AddOrUpdate<FreeEditionControlJob>(job => job.Execute(0), "00 02 * * *"); return; } }

    Startup.cs (Web.Host) public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) { .... if (WebConsts.HangfireDashboardEnabled) { //Hangfire dashboard &server(Enable to use Hangfire instead of default job manager) app.UseHangfireDashboard(WebConsts.HangfireDashboardEndPoint, new DashboardOptions { Authorization = new[] {new AbpHangfireAuthorizationFilter(AppPermissions.Pages_Administration_HangfireDashboard)} }); app.UseHangfireServer(); HangfireService.InitializeJobs(); } .... }

  • 0
    ismcagdas created
    Support Team

    Hi **@QuickApp **

    I'm not %100 sure but this might help you. Instead of just using AddOrUpdate, do it like below. First remove the existing job and create it again.

    var qTenantInvoiceJob = IocManager.Resolve<QTenantInvoiceJob>();
    
    RecurringJob.RemoveIfExists("QTenantInvoiceJob");
    RecurringJob.AddOrUpdate("QTenantInvoiceJob", () => qTenantInvoiceJob.Execute(0), Cron.Daily(12, 00), TimeZoneInfo.Utc);