Module: Sidekiq::Routing::Mover

Defined in:
lib/sidekiq/routing/mover.rb

Overview

Relocates an already-enqueued job payload to another queue by rewriting the “queue” field inside the payload and writing it straight to Redis.

It deliberately bypasses the client middleware chain. Going through Sidekiq::Client.push would (a) risk re-diverting the job via our own client middleware and (b) make sidekiq-unique-jobs try to re-acquire a lock that the in-flight original still holds, which can fail the push and drop the job on a server-side park. Moving the raw payload sidesteps both.

Used by the server middleware (park), the Sweeper, and the ParkedProcessor.

Class Method Summary collapse

Class Method Details

.move(item, to_queue, extra = {}) ⇒ Object

item: the existing job hash (a Sidekiq::JobRecord#item or job hash) to_queue: destination queue name extra: payload keys to merge in (e.g. the original-queue stamp)



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sidekiq/routing/mover.rb', line 20

def move(item, to_queue, extra = {})
  target = to_queue.to_s
  payload = item.merge("queue" => target).merge(extra)
  json = Sidekiq.dump_json(payload)

  Sidekiq.redis do |conn|
    conn.sadd("queues", target) # keep the queue visible in the Web UI
    conn.lpush("queue:#{target}", json)
  end
  true
end