Skip to content

Instantly share code, notes, and snippets.

@rosa
Last active September 5, 2025 01:54
Show Gist options
  • Select an option

  • Save rosa/57041c184068a76a77141c8b2765c511 to your computer and use it in GitHub Desktop.

Select an option

Save rosa/57041c184068a76a77141c8b2765c511 to your computer and use it in GitHub Desktop.
Simple script to move jobs scheduled in the future with resque-scheduler to Solid Queue or any other adapter
# To count jobs still scheduled in the future with Resque
# Resque.redis.zcount(:delayed_queue_schedule, "-inf", "+inf")
# `job_data` from Resque (Redis)
def decode_job(job_data)
job_json = JSON.parse(job_data).dig("args").first
job_class = job_json["job_class"]
job_arguments = ActiveJob::Arguments.deserialize(job_json["arguments"])
{ job_class: job_class, job_arguments: job_arguments }
rescue ActiveJob::DeserializationError
end
# Depending on the number of jobs, this will need to be done on a loop until there aren't any more jobs
# In our case, most jobs scheduled in the future were stored in the DB using an in-house gem, so we had
# less than 100,000 jobs to move from Resque. All of those were ActiveRecord::DestroyJob
job_timestamps = Array(Resque.redis.zrange(:delayed_queue_schedule, 0, 100000))
jobs = []
job_timestamps.each do |timestamp|
time = Time.at(timestamp.to_i)
next if time < 10.minutes.from_now # let those be dispatched by Resque
key = "delayed:#{timestamp}"
Resque.redis.lrange(key, 0, -1).each do |job_data|
job = decode_job(job_data)
if job && (job_class = job[:job_class].safe_constantize)
jobs << job_data
# This would enqueue that job in the adapter the job is configured for (:solid_queue or any other)
job_class.set(wait_until: time).perform_later(*job[:job_arguments])
Resque.send :remove_delayed_job, job_data
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment