What is the best way to schedule an β€œever” task on rails at midnight?

We have a Rails 4 application. What is the best way to schedule a task wheneveron rails at midnight using daylight saving time?

We need to send an email at 11.58 pm on the night of the daytime report.

We use tzinfo gem

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

Don't send emails at that time.

+4
source share
1 answer

This works around a time zone problem, the server is in UTC, and users in a different time zone (with daylight saving time). define 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 this helps you.

+6
source

All Articles