Skip to content

Instantly share code, notes, and snippets.

@larryzhao larryzhao/migrate.rb
Last active Oct 8, 2016

Embed
What would you like to do?
Migrate Sidekiq.
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
You can’t perform that action at this time.