We are leaving Russia. We are against aggression and war with Ukraine. It is a tragedy for our nations, it is a nightmare

Delayed jobs scheduling an hour in the future

Hi,

I am using Hangfire to schedule a one time method to be called and executed at a specific date in the future. This was working fine until daylight savings time came in to effect and now the Hangfire server seems to be adding an extra hour on to the datetime that a job is scheduled for. e.g. my application will set the time for the background job to be executed at to 17:45 (GMT+1) but Hangfire will schedule the job to be ran at 18:45 instead.

This only happens in a production environment that is configured as an app service in Northern Europe in Azure. The scheduled time is set correctly when running through my local machine. I’m convinced it is something to do with the timezone of the production app service or something that I haven’t configured on Hangfire start up. I have tried multiple different bits of code including a check for DST and then subtracting an hour from the scheduled time, changing the BackgroundJob.Schedule method to use the TimeZone parameters instead of DateTimeOffset and also converting the schedule date to UTC first. All of these have the same outcome of the job being scheduled an hour later than intended.

Please see my invocation of the delayed job function below:

var jobID = BackgroundJob.Schedule(() => GenericMethod(userID, customerID, null), scheduledDate);

where scheduledDate is a DateTime object.

Any help would be greatly appreciated. Thanks.

I managed to finally solve this issue. It wasn’t anything to do with Hangfire in the end as was to do with the timezone of the actual app services in Azure. As I mentioned above, the app services are in “North Europe” but I couldn’t find out any timezone information for them. I found out that you can change the timezone by adding an entry in the application settings. After adding this setting and restarting the app services, Hangfire is scheduling the jobs as expected again.