mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 14:12:10 +08:00

As we’re currently using a namespace for Sidekiq, in order to upgrade to the latest version, we need to drop it as it’s not supported anymore. The recommended way is to use a different Redis DB for Sidekiq. This patch uses a different config for Sidekiq and also takes care of migrating existing jobs (in queues and the retry and scheduled sets).
41 lines
909 B
Ruby
41 lines
909 B
Ruby
# frozen_string_literal: true
|
|
|
|
# TODO (2025-03-03): delete this once the migration is propagated everywhere
|
|
# (in about 6 months or so)
|
|
class SidekiqMigration
|
|
delegate :old_pool, to: :Sidekiq
|
|
|
|
def self.call
|
|
new.call
|
|
end
|
|
|
|
def call
|
|
migrate_all_queues
|
|
migrate(klass: Sidekiq::RetrySet)
|
|
migrate(klass: Sidekiq::ScheduledSet)
|
|
end
|
|
|
|
private
|
|
|
|
def migrate_all_queues
|
|
migrate(
|
|
old_jobs: -> { Sidekiq::Queue.all.flat_map(&:to_a) },
|
|
enqueue_jobs: ->(job) { client.push(job.item) },
|
|
)
|
|
end
|
|
|
|
def migrate(
|
|
klass: nil,
|
|
old_jobs: -> { klass.new.to_a },
|
|
enqueue_jobs: ->(job) { klass.new.schedule(job.score, job.item) }
|
|
)
|
|
jobs_to_migrate = Sidekiq::Client.via(old_pool, &old_jobs)
|
|
jobs_to_migrate.each(&enqueue_jobs)
|
|
Sidekiq::Client.via(old_pool) { jobs_to_migrate.each(&:delete) }
|
|
end
|
|
|
|
def client
|
|
@client ||= Sidekiq::Client.new
|
|
end
|
|
end
|