Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to schedule `whenever` task in rails in midnight usa?

We have a Rails 4 application . What is the best way to schedule whenever task in rails in midnight usa with daylight saving ?

We need to send email at 11.58pm in night of a day's report .

We are using tzinfo gem

TZInfo::Timezone.get('America/Denver').local_to_utc(Time.parse('11:58pm')).strftime('%H:%M%p')

is not sending email at the time .

like image 424
Debadatt Avatar asked Feb 07 '23 02:02

Debadatt


1 Answers

This works around the timezone issue, server is at UTC and users in another time zone (with daylight saving time). define a local action and use in cronjob.

schedule.rb

require "tzinfo"

def local(time)
  TZInfo::Timezone.get('America/Denver').local_to_utc(Time.parse(time))
end

every :sunday, at: local("11:58 pm") do
 #your email sending task
end

hope it will help you.

like image 188
Rehan Munir Avatar answered Feb 27 '23 12:02

Rehan Munir