Module: Resque::FairShare::Migration

Defined in:
lib/resque/fair_share/migration.rb

Overview

Backfills per-partition sub-queues from the existing main Resque queue. Safe to run while workers are active (new jobs are dual-written by hooks).

Constant Summary collapse

BATCH_SIZE =
500

Class Method Summary collapse

Class Method Details

.perform(queue, partition_key: nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/resque/fair_share/migration.rb', line 8

def self.perform(queue, partition_key: nil)
  key = partition_key || Resque::FairShare.configuration.partition_key
  namespace = Resque.redis.namespace
  queue_key = "#{namespace}:queue:#{queue}"
  raw_redis = Resque.redis.redis

  offset = 0
  migrated = 0

  loop do
    items = raw_redis.lrange(queue_key, offset, offset + BATCH_SIZE - 1)
    break if items.empty?

    migrated += migrate_batch(items, queue, key, namespace, raw_redis)
    offset += BATCH_SIZE
  end

  migrated
end