Skip to content

Instantly share code, notes, and snippets.

@larryzhao
Last active October 8, 2016 16:20
Show Gist options
  • Save larryzhao/a98bfb67dd98c1c61ddb5ede58ef38f8 to your computer and use it in GitHub Desktop.
Save larryzhao/a98bfb67dd98c1c61ddb5ede58ef38f8 to your computer and use it in GitHub Desktop.
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