Skip to content

Instantly share code, notes, and snippets.

@teamon
Created October 20, 2012 21:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save teamon/3924858 to your computer and use it in GitHub Desktop.
Save teamon/3924858 to your computer and use it in GitHub Desktop.
clockwork + sidekiq integration
require 'clockwork'
require 'sidekiq'
# load all jobs from app/jobs directory
# no need to load rails env, we only care about classes
# (#perform method is not invoked in this process)
Dir["app/jobs/*"].each {|f| load f }
module Clockwork
every(1.day, 'midnight.job', :at => '00:00'){
MidnightJob.perform_async(1,2,3)
}
end
@passcod
Copy link

passcod commented Oct 20, 2012

Note that Sidekiq has a perform_at method, which might be more accurate because of polling times, etc. For maximum accuracy, I would rewrite the above as:

every(1.day, 'midnight.job', at: '23:59') do
  t = Time.new Time.at(Time.new+100).to_s.sub(/\s.+\s/," 00:00:00 ")
  # ^ There must be a better way to do this, can't think right now.

  MidnightJob.perform_at t, 1, 2, 3
end

which simply executes a minute before midnight, and schedules a job to be run at exactly midnight.

@sergiopvilar
Copy link

Not a good choice skip rails if you are using different configuration for Redis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment