Running Rails 4.2.0 so I am using the ActiveJob w/ Sidekiq backend. I need to invoke regularly scheduled background jobs so I am hoping to use Clockwork, but I haven't seen any examples of how to use it with ActiveJob.
Here is my lib/clock.rb based off the Clockwork Github example:
require 'activejob'
module Clockwork
handler do |job, time|
puts "Running #{job}, at #{time}"
ProductUpdateJob.perform_later
end
every(30.seconds, 'ProductUpdateJob.perform_later')
end
Update:
I was able to get it to work for my situation, but I'm not entirely satisfied with the solution since I am having to load the entire environment. I would only like to require the bare minimum to run the ActiveJobs.
Dir["./jobs/*.rb"].each {|file| require file }
require 'clockwork'
require './config/boot'
require './config/environment'
#require 'active_job'
#require 'active_support'
module Clockwork
handler do |job, time|
puts "Running #{job}, at #{time}"
#send("#{job}")
#puts "#{job}".constantize
"#{job}".constantize.perform_later
end
every(10.seconds, 'ProductUpdateJob')
end