Sha256: 4f611384a89dcea07602858e46b121e5ed1c8d911b566d102313a04bcff70959

Contents?: true

Size: 815 Bytes

Versions: 7

Compression:

Stored size: 815 Bytes

Contents

require 'resque/integration/unique'

namespace :resque do
  namespace :lock do
    task expire_all: :environment do
      puts "Start expiring all resque locks"

      redis = ::Resque.redis
      cursor = 0
      batch_size = 10_000
      timeout = ::Resque::Integration::Unique::LOCK_TIMEOUT
      count = 0
      pattern = "lock:*"

      loop do
        cursor, keys = redis.scan(cursor, count: batch_size, match: pattern)
        cursor = cursor.to_i

        unless keys.empty?
          redis.pipelined do
            keys.each do |key|
              redis.expire(key, timeout)
            end
          end

          count += keys.size
          puts "Expired #{count}..."
        end

        break if cursor.zero?
      end

      puts "Expired total #{count} keys."
      puts "Done."
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
resque-integration-3.8.2 lib/resque/integration/tasks/lock.rake
resque-integration-3.8.1 lib/resque/integration/tasks/lock.rake
resque-integration-3.8.0 lib/resque/integration/tasks/lock.rake
resque-integration-3.7.1 lib/resque/integration/tasks/lock.rake
resque-integration-3.5.1 lib/resque/integration/tasks/lock.rake
resque-integration-3.5.0 lib/resque/integration/tasks/lock.rake
resque-integration-3.4.1 lib/resque/integration/tasks/lock.rake