Sha256: dfaec15bf4bd07776c2853444eab41b7c2a73c7fced7f34df68316ca01111df2

Contents?: true

Size: 1.57 KB

Versions: 14

Compression:

Stored size: 1.57 KB

Contents

local function find_digest_in_process_set(digest, threshold)
  local process_cursor = 0
  local job_cursor     = 0
  local pattern        = "*" .. digest .. "*"
  local found          = false

  log_debug("Searching in process list",
            "for digest:", digest,
            "cursor:", process_cursor)

  repeat
    local process_paginator   = redis.call("SSCAN", "processes", process_cursor, "MATCH", "*")
    local next_process_cursor = process_paginator[1]
    local processes           = process_paginator[2]
    log_debug("Found number of processes:", #processes, "next cursor:", next_process_cursor)

    for _, process in ipairs(processes) do
      local workers_key = process .. ":work"
      log_debug("searching in process set:", process,
                "for digest:", digest,
                "cursor:", process_cursor)

      local jobs = redis.call("HGETALL", workers_key)

      if #jobs == 0 then
        log_debug("No entries in:", workers_key)
      else
        for i = 1, #jobs, 2 do
          local jobstr = jobs[i +1]
          if string.find(string.gsub(jobstr, ':RUN', ''), string.gsub(digest, ':RUN', '')) then
            log_debug("Found digest", digest, "in:", workers_key)
            found = true
            break
          end

          local job = cjson.decode(jobstr)
          if job.payload.created_at > threshold then
            found = true
            break
          end
        end
      end

      if found == true then
        break
      end
    end

    process_cursor = next_process_cursor
  until found == true or process_cursor == "0"

  return found
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-8.0.10 lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_process_set.lua
sidekiq-unique-jobs-7.1.33 lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_process_set.lua
sidekiq-unique-jobs-7.1.32 lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_process_set.lua
sidekiq-unique-jobs-8.0.9 lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_process_set.lua
sidekiq-unique-jobs-8.0.8 lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_process_set.lua
sidekiq-unique-jobs-8.0.7 lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_process_set.lua
sidekiq-unique-jobs-8.0.6 lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_process_set.lua
sidekiq-unique-jobs-7.1.31 lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_process_set.lua
sidekiq-unique-jobs-8.0.5 lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_process_set.lua
sidekiq-unique-jobs-8.0.4 lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_process_set.lua
sidekiq-unique-jobs-7.1.30 lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_process_set.lua
sidekiq-unique-jobs-8.0.3 lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_process_set.lua
sidekiq-unique-jobs-8.0.2 lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_process_set.lua
sidekiq-unique-jobs-8.0.1 lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_process_set.lua