-
-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent reaping of active jobs (#493)
* Begin prevention of reaping active jobs * Prevent reaping of active jobs Close #488 * Don't reek * Mandatory rubocop commit
- Loading branch information
Showing
11 changed files
with
131 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_process_set.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
local function find_digest_in_process_set(digest) | ||
local process_cursor = 0 | ||
local job_cursor = 0 | ||
local pattern = "*" .. digest .. "*" | ||
local found = false | ||
|
||
log_debug("searching in list processes:", | ||
"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 | ||
log_debug("searching in process set:", process, | ||
"for digest:", digest, | ||
"cursor:", process_cursor) | ||
|
||
local job = redis.call("HGET", process, "info") | ||
|
||
if string.find(job, digest) then | ||
log_debug("Found digest", digest, "in process:", process) | ||
found = true | ||
break | ||
end | ||
end | ||
|
||
process_cursor = next_process_cursor | ||
until found == true or process_cursor == "0" | ||
|
||
return found | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,10 +9,12 @@ module Orphans | |
# | ||
# @author Mikael Henriksson <[email protected]> | ||
# | ||
# rubocop:disable Metrics/ClassLength | ||
class Reaper | ||
include SidekiqUniqueJobs::Connection | ||
include SidekiqUniqueJobs::Script::Caller | ||
include SidekiqUniqueJobs::Logging | ||
include SidekiqUniqueJobs::JSON | ||
|
||
# | ||
# Execute deletion of orphaned digests | ||
|
@@ -141,7 +143,7 @@ def orphans | |
# @return [false] when no job was found for this digest | ||
# | ||
def belongs_to_job?(digest) | ||
scheduled?(digest) || retried?(digest) || enqueued?(digest) | ||
scheduled?(digest) || retried?(digest) || enqueued?(digest) || active?(digest) | ||
end | ||
|
||
# | ||
|
@@ -185,6 +187,20 @@ def enqueued?(digest) | |
end | ||
end | ||
|
||
def active?(digest) | ||
Sidekiq.redis do |conn| | ||
procs = conn.sscan_each("processes").to_a.sort | ||
|
||
result = conn.pipelined do | ||
procs.map do |key| | ||
conn.hget(key, "info") | ||
end | ||
end | ||
|
||
result.flatten.compact.any? { |job| load_json(job)[LOCK_DIGEST] == digest } | ||
end | ||
end | ||
|
||
# | ||
# Loops through all the redis queues and yields them one by one | ||
# | ||
|
@@ -233,5 +249,6 @@ def in_sorted_set?(key, digest) | |
conn.zscan_each(key, match: "*#{digest}*", count: 1).to_a.any? | ||
end | ||
end | ||
# rubocop:enable Metrics/ClassLength | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters