Hello, i have been facing this issue for the past week. All of the Recurring jobs in Hangfire got Next Execution date a past date. I have noticed that if i trigger any job, it will be executed and the Next Execution date is set properly. But when the time comes up it does not executed at all and the Next Execution date is set to past date again. The only solution i managed to find it to delete them all from the database, DELETE FROM [Hangfire].[Set] and DELETE FROM [Hangfire].[Hash] and re-create them.
Could you please advise, how to avoid this kind of issues?
Thank you in Advance
Just a wild guess, but do the machine on which the job is enqueued and the machine which executes the job has the same system time? This kind of sounds like a time zone mismatch.
Hello @Tieson_Trowbridge, thank you for your response. I am going to check the timezones and see if there is any mismatch. If this is the issue, i will let you know
Hello @Tieson_Trowbridge,
Could you take a look on the timezones below and let me know based on your experience if there is any missmatch?
Host Machine
Tue 25 Oct 2022 01:09:44 PM UTC
Docker Container
Tue Oct 25 13:10:37 UTC 2022
Database
select current_timezone()
(UTC+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius
Hard to say based on those values, unless the host machine and the Docker image really are using the UTC time zone. At a minimum, those two hosts are within error margins, so that shouldn’t be the problem. If both of those differ from your database host, that might cause an issue; I don’t know if the Hangfire persistence code writes it’s own timestamps or if it relies on things like sysdatetime()
in the database.
Assuming “host machine” is your development workstation, you can get your system’s time zone via TimeZoneInfo. Here’s an example: TimeZoneInfo.Local Property (System) | Microsoft Learn
If you have something like LinqPad, you don’t even need to write an executable - just copy the four lines of code from the main() method, drop them in a new LinqPad editor, and run it.
I did an implementation in the application to allow the user to set the timezone for a recurring job. The options are UTC or Local. I tried to use the Local and in the Hangfire i see that it changed to Etc/UTC but still when the time comes the job did not run and the next execution date remained the same.
The Next Execution date for a particular job it does not update in the database. Is there any chance that the database user has no permission to update the hangfire tables?
@Tieson_Trowbridge i did synchronize the host machine and the database server on the same timezone (GTM+2) but still it does not work. I tried to change the Timezone parameter on the hangfire to Europe/Vilnius which is GTM+2 instead of UTC but it still does not work.
After a long investigation i think that the solution to this kind of issue is to drop the hangfire tables from the database and re-build the application. For some reason i did that action and the jobs synchronized correctly with the server timezone and start to work as expected.