Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sidekiq to execute at specific time in every timezones

Using Sidekiq, what are the strategy to have it execute at a particular time in every time zone?

For example, I need Sidekiq to perform a task every day at the following time and time zones across the world:

... 8:00 PM EST 8:00 PM CST 8:00 PM MST 8:00 PM PST ...

like image 333
Chad Taylor Avatar asked Dec 17 '25 21:12

Chad Taylor


1 Answers

I would just run the same job at the start of each hour. You might want to use cron to run the job each hour or have a look at this list on how to create recurring jobs in Sidekiq.

The first step within the job is to figure out all time zones in which it is 8AM right now:

8am_time_zones = ActiveSupport::TimeZone.all
                                        .select { |tz| tz.now.hour == 8 }
                                        .map { |tz| tz.tzinfo.name }
#=> ["America/Los_Angeles", "America/Tijuana", "America/Phoenix"]

With this list you can easily load users from your database who live in one of the time zones (assuming you stored the users' time zone in this format) and send them the email:

User.where(time_zone: 8am_time_zones).find_each do |user|
  # email_newsletter(recipient: user)
end
like image 186
spickermann Avatar answered Dec 20 '25 09:12

spickermann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!