-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Leave Queues with single responsibility - track eventually-consistent list of paused queues.
- Loading branch information
Showing
10 changed files
with
273 additions
and
203 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# frozen_string_literal: true | ||
|
||
module Sidekiq | ||
module Pauzer | ||
class Repository | ||
include Enumerable | ||
|
||
REDIS_KEY = "sidekiq-pauzer" | ||
|
||
# @overload each | ||
# @return [Enumerator<String>] | ||
# | ||
# @overload each(&block) | ||
# For a block { |queue_name| ... } | ||
# @yieldparam queue_name [String] | ||
# @return [self] | ||
def each | ||
return to_enum __method__ unless block_given? | ||
|
||
redis_call("SMEMBERS", REDIS_KEY).each { yield _1.freeze } | ||
|
||
self | ||
end | ||
|
||
# @param queue_name [#to_s] | ||
# @return [void] | ||
def add(queue_name) | ||
redis_call("SADD", REDIS_KEY, queue_name.to_s) | ||
nil | ||
end | ||
|
||
# @param queue_name [#to_s] | ||
# @return [void] | ||
def delete(queue_name) | ||
redis_call("SREM", REDIS_KEY, queue_name.to_s) | ||
nil | ||
end | ||
|
||
# @param name [#to_s] | ||
# @return [void] | ||
def include?(queue_name) | ||
redis_call("SISMEMBER", REDIS_KEY, queue_name.to_s).positive? | ||
end | ||
|
||
private | ||
|
||
def redis_call(...) | ||
Sidekiq.redis { _1.call(...) } | ||
end | ||
end | ||
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
Oops, something went wrong.