I need to schedule recurring jobs based on local time, for example 02:00 CET (which is UTC+1 normally and UTC+2 during daylight savings time aka “summer time”).
I know this introduces some problems when switching to/from summer to winter time (there is an hour which does not exist and another one that exists twice), but I’m sure these could be dealed with.
As a current workaround I could probably create separate cron expressions for summer and winter time, but as the switching dates change from year to year, I’d have to do this for each year separately, which is not an option.
I’m surprised nobody seems to have asked for this yet, but I understand that Hangfire was built around “fire-and-forget” tasks primarily and the recurring tasks are not a core feature.
If I wanted to implemented this myself (or at least give it a try) where would I start?
Local time oriented schedules would be very nice. We have some task which should be executed at set times, like midnight on a daylight savings based machine.
@odinserj Could you maybe shed light on this feature request? I wonder what prevents Hangfire from taking timezones into account. A desired very common tasks is just to execute a task after midnight (local time). Because the runner is in a time-zone that uses daylight savings time, I cannot just correct the task by a fixed number of hours.
I would also be interested in this as well. We have a need where a customer is sending a file at a specific time and need to run it immediately after they send it (which is at 12:30AM Central time) so we want to make sure our recurring task executes at 12:45AM Central in both CDT and CST throughout the year.
Hi!
I’ve the same problem, but it seems that nobody has found the solution yet.
I’m able to schedule my recurring jobs using cron expressions, but the expressions are intended to be used using my current time (UTC +2), while the server uses UTC time.
How can I resolve this mismatch?
This feature is already implemented, but available only in pre-release version 1.4.0-beta1. So you can use the following syntax to work with time zones:
Here are some facts about current implementation, they will be moved to the docs:
Default time zone is UTC. This may be confusing for users of Quartz.NET, Cron program in Linux, etc, that use local time by default. But switch to local time by default will introduce breaking changes, so it will be performed in version 2.0.
Windows Time Zone IDs are being used to store time zones. So there may be some issues when your Hangfire infrastructure contains both Windows and Linux. I thought about using NodaTime and its DateTimeProviders.Tzdb that uses IANA time zone ids, but it is overkill. Custom time zone providers may be implemented for Hangfire to handle this issue later.
Issues with Mono. TimeZoneInfo in Mono has some critical flaws in the latest stable Mono release at the time of this writing (2.10.8). TimeZoneInfo.Local has particular issues on the latest tested version of Mono. On Windows, TimeZoneInfo.Local throws TimeZoneNotFoundException. On Unix it returns a TimeZoneInfo with an Id of “Local”, which isn’t terribly useful (although it may contain the correct rules). – from http://nodatime.org/1.3.x/userguide/mono.html. This may be solved later, with custom time zone providers.
Great, It works! Thanks!
One last question. From version 1.4.0beta1 the app configuration is changed, in fact UseHangfire is now obsolete.
I didn’t find nothing about UseHangfireServer and UseHangfireDashboard methods, how should I use them to configure the app?