Hangfire - Execution function time is not match with the scheduled job time

53 views Asked by At

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);
2

There are 2 answers

0
Umesh Shende On BEST ANSWER

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).
});
1
J.Memisevic On

Schedule settings in Hangfire is not for job execution - rather for job enqueue. That means that job will be placed in queue and executed when one of the workers on hangfire server is available.

There can be delay if:

  1. something else is executing - or server has some unexpected load.
  2. hangfire reads job definition from database, and persists new state every time so if you database is loaded at the moment - delay can happen.