HangfireIO / Hangfire

An easy way to perform background job processing in .NET and .NET Core applications. No Windows Service or separate process required
https://www.hangfire.io
Other
9.44k stars 1.71k forks source link

Execution function time is not match with the scheduled job time #2368

Closed umeshshende closed 9 months ago

umeshshende commented 9 months ago

We have scheduled TriggerdNotitication() function at 12.10.10PM

Expected would be TriggerdNotitication() will be executed at 12.10.10PM But Actual TriggerdNotitication() is executed at 12.10.25PM

Version: 1.8.2 why this taken extra 15 sec sometimes its increase to 20sec sometimes its 14 sec it is not exact match with scheduled time

we have found this major issue as notification is delay instead within 1min it sent around 45sec or 40 sec

   TimeZoneInfo siteTZ = TimeZoneInfo.FindSystemTimeZoneById(SiteClient.SiteTimeZone);
    scheduleTime = TimeZoneInfo.ConvertTime(scheduleTime, TimeZoneInfo.Utc, siteTZ);
     scheduleTime = scheduleTime.AddHours(HelperMethods.GetHangireAWTimeZoneOffset());

     //Removing ACP-> PerItemItem from scheduled time
      scheduleTime = scheduleTime.AddMinutes(-Convert.ToDouble(perItemTiggerTime));

      BackgroundJob.Schedule(() => TriggerdNotitication(eventID, triggerTime), scheduleTime);
Liebeck commented 9 months ago

@umeshshende The default value to check the Hangfire queue is set to 15 seconds. You can decrease this value if you want to reduce the delay

umeshshende commented 9 months ago

Yes, Found the solution reduced the default queueing time 15 seconds to 5seconds

GlobalConfiguration.Configuration.UseSqlServerStorage(ConfigurationManager.ConnectionStrings["db_connection"].ConnectionString,
    new Hangfire.SqlServer.SqlServerStorageOptions
    { QueuePollInterval = TimeSpan.FromSeconds(5) });

app.UseHangfireServer(new BackgroundJobServerOptions()
{
    SchedulePollingInterval = TimeSpan.FromSeconds(5).
});