Sha256: 6ebec86971f82254be132b057651e670455838757109ecf137863c7971d3b538

Contents?: true

Size: 1.86 KB

Versions: 8

Compression:

Stored size: 1.86 KB

Contents

local queue         = "queue:" .. KEYS[1]
local unique_digest = KEYS[2]

local function delete_from_sorted_set(name, digest)
  local per   = 50
  local total = redis.call('zcard', name)
  local index = 0
  local result
  -- redis.log(redis.LOG_DEBUG, "delete_from_sorted_set("..name..","..digest..")")
  while (index < total) do
    -- redis.log(redis.LOG_DEBUG, "delete_from_sorted_set("..name..","..digest..") - "..index.."-"..per)
    local items = redis.call('ZRANGE', name, index, index + per -1)
    for _, item in pairs(items) do
      -- redis.log(redis.LOG_DEBUG, "delete_from_sorted_set("..name..","..digest..") - current item: " .. item)
      if string.find(item, digest) then
        -- redis.log(redis.LOG_DEBUG, "delete_from_sorted_set("..name..","..digest..") - deleting item")
        redis.call('ZREM', name, item)
        result = item
        break
      end
    end
    index = index + per
  end
  return result
end

local per     = 50
local total   = redis.call('LLEN', queue)
local index   = 0
local result  = nil

-- redis.log(redis.LOG_DEBUG, "delete_job_by_digest.lua - looping through: " .. queue)
while (index < total) do
  -- redis.log(redis.LOG_DEBUG, "delete_job_by_digest.lua - " .. index .. "-" .. per)
  local items = redis.call('LRANGE', queue, index, index + per -1)
  for _, item in pairs(items) do
    -- redis.log(redis.LOG_DEBUG, "delete_job_by_digest.lua - item: " .. item)
    if string.find(item, unique_digest) then
      -- redis.log(redis.LOG_DEBUG, "delete_job_by_digest.lua - found item with digest: " .. unique_digest .. " in: " ..queue)
      redis.call('LREM', queue, 1, item)
      result = item
      break
    end
  end
  index = index + per
end

if result then
  return result
end

result = delete_from_sorted_set('schedule', unique_digest)
if result then
  return result
end

result = delete_from_sorted_set('retry', unique_digest)
return result

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-6.0.6 redis/delete_job_by_digest.lua
sidekiq-unique-jobs-6.0.5 redis/delete_job_by_digest.lua
sidekiq-unique-jobs-6.0.4 redis/delete_job_by_digest.lua
sidekiq-unique-jobs-6.0.3 redis/delete_job_by_digest.lua
sidekiq-unique-jobs-6.0.2 redis/delete_job_by_digest.lua
sidekiq-unique-jobs-6.0.1 redis/delete_job_by_digest.lua
sidekiq-unique-jobs-6.0.0 redis/delete_job_by_digest.lua
sidekiq-unique-jobs-6.0.0.rc8 redis/delete_job_by_digest.lua