Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hangfire CRON in UTC time

Tags:

I am trying to configure a recurring task in my MVC application starting at 00:00 every day. I know this can be achieved by RecurringJob.AddOrUpdate(() => Console.Write("Easy!"), Cron.Daily);. Now my question is does hangfire cron work on basis of UTC time or the local time at server. If it works on local time, is there a way to run that on UTC time? I have to do this because this will be a day end process and all the scheduled tasks are scheduled based on the Universal time in my database.

like image 288
Anas Shahid Avatar asked Jul 09 '16 14:07

Anas Shahid


People also ask

Does hangfire use UTC?

Default time zone is UTC. 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.

How do I change timezone in hangfire?

To execute a job in local time zone you can use TimeZoneInfo. Local . Show activity on this post. To run in a specific timezone instead of UTC, look up the TimeZoneInfo you want.

What is Cron in hangfire?

The Cron class contains different methods and overloads to run jobs on a minute, hourly, daily, weekly, monthly and yearly basis. You can also use CRON expressions to specify a more complex schedule: RecurringJob. AddOrUpdate("powerfuljob", () => Console.


2 Answers

To execute a job in UTC time zone, you can provide TimeZoneInfo as TimeZoneInfo.Utc while defining your jobs.

RecurringJob.AddOrUpdate(() => Console.Write("Easy!"), Cron.Daily, TimeZoneInfo.Utc); 

To execute a job in local time zone you can use TimeZoneInfo.Local.

like image 174
Yogi Avatar answered Sep 21 '22 18:09

Yogi


To run in a specific timezone instead of UTC, look up the TimeZoneInfo you want. The task will run at midnight.

var manager = new RecurringJobManager(); manager.AddOrUpdate("some-id", Job.FromExpression(() => Method()),     Cron.Daily(),     TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")); 
like image 45
Arun Prasad E S Avatar answered Sep 17 '22 18:09

Arun Prasad E S