Last active
October 8, 2016 16:20
-
-
Save larryzhao/a98bfb67dd98c1c61ddb5ede58ef38f8 to your computer and use it in GitHub Desktop.
Migrate Sidekiq.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jobs = [] | |
# Read from Old Sidekiq | |
ss = Sidekiq::ScheduledSet.new | |
ss.each do |job| | |
value = JSON.parse(job.value) | |
if value["class"] == "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper" | |
# this is an active job | |
args = value["args"].first | |
jobs << { | |
:t => "aj", | |
:job_class => args["job_class"], | |
:arguments => args["arguments"], | |
:score => job.score | |
} | |
else | |
# this is an Sidekiq Worker | |
jobs << { | |
:t => "sk", | |
:job_class => value["class"], | |
:arguments => value["args"], | |
:score => job.score | |
} | |
end | |
end;nil | |
# Enqueue into new Sidekiq. | |
jobs.each do |job| | |
puts "Doing #{job[:t]} - #{job[:job_class]} - #{job[:arguments]} - #{job[:score]}" | |
time = job[:score] <= Time.now.to_i ? Time.now + 1.minute : Time.at(job[:score]) | |
if job[:t] == "aj" | |
# ActiveJob | |
job[:job_class].constantize.set(:wait_until => time).perform_later(*job[:arguments]) | |
else | |
# Sidekiq | |
job[:job_class].constantize.perform_at(time, *arguments) | |
end | |
end;nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment