I’ve been implementing Delayed Job to poll Twitter every minute for changes. However, it was immediately running everything and ignoring the run_at time in the database. Or so I thought.
Upon inspection of the code for Delayed Job, it is polling the database time to UTC and not local time.
def self.db_time_now (ActiveRecord::Base.default_timezone == :utc) ? Time.now.utc : Time.now end
Delayed::Job.enqueue PollTwitter.new(), 0, 1.minutes.from_now
has now become
Delayed::Job.enqueue PollTwitter.new(), 0, 1.minutes.from_now.getutc
Four hours is a large difference.
Note: Normally I would just run this as a cron job, but Heroku will only run cron once per hour.