sidekiq-pauzer 1.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +1 -1
- data/lib/sidekiq/pauzer/adapters/redis.rb +3 -3
- data/lib/sidekiq/pauzer/adapters/redis_client.rb +6 -7
- data/lib/sidekiq/pauzer/basic_fetch.rb +18 -11
- data/lib/sidekiq/pauzer/patches/queue.rb +1 -0
- data/lib/sidekiq/pauzer/patches/web_action.rb +1 -0
- data/lib/sidekiq/pauzer/patches/web_application.rb +1 -0
- data/lib/sidekiq/pauzer/queues.rb +14 -22
- data/lib/sidekiq/pauzer/version.rb +1 -1
- data/lib/sidekiq/pauzer.rb +56 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bfbbdbcf00da656eb48a8dccb0807b68e8554f6a02c6ed54e954f19d0ddd46b
|
4
|
+
data.tar.gz: 4887f3d8e032f2a48327e4e40ded771cf8552620f82e6b2744ce0625b0d89369
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73d2a4ae6200e308e83052947614759ea3db81bf22d481d67ae2d4c83d6531aa1c267f0662e8e231c0bad4e5091d6e99e568ae16e8919af016b55f742d4f243e
|
7
|
+
data.tar.gz: ca0824fa84c56ef904cac670fe5ed43d1f90701c6983ca0710cfa5d71cb01dd9a05ceeed45c8d98c9c32eb4a03192eae19120bf1fd7c7ac8e86f09baaa33bb99
|
data/README.adoc
CHANGED
@@ -13,15 +13,15 @@ module Sidekiq
|
|
13
13
|
false
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def add(redis, key, queue)
|
17
17
|
redis.sadd(key, queue)
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
20
|
+
def remove(redis, key, queue)
|
21
21
|
redis.srem(key, queue)
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
24
|
+
def list(redis, key)
|
25
25
|
# Cursor is not atomic, so there may be duplicates because of
|
26
26
|
# concurrent update operations
|
27
27
|
# See: https://redis.io/commands/scan/#scan-guarantees
|
@@ -1,31 +1,30 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "../runtime"
|
4
|
+
|
3
5
|
module Sidekiq
|
4
6
|
module Pauzer
|
5
7
|
module Adapters
|
6
8
|
# redis-client adapter
|
7
9
|
module RedisClient
|
8
|
-
SIDEKIQ_SEVEN = Gem::Version.new("7.0.0").freeze
|
9
|
-
SIDEKIQ_VERSION = Gem::Version.new(Sidekiq::VERSION).freeze
|
10
|
-
|
11
10
|
class << self
|
12
11
|
def adapts?(redis)
|
13
|
-
return true if SIDEKIQ_SEVEN
|
12
|
+
return true if Runtime::SIDEKIQ_SEVEN
|
14
13
|
return true if defined?(::RedisClient) && redis.is_a?(::RedisClient)
|
15
14
|
return true if defined?(::RedisClient::Decorator::Client) && redis.is_a?(::RedisClient::Decorator::Client)
|
16
15
|
|
17
16
|
false
|
18
17
|
end
|
19
18
|
|
20
|
-
def
|
19
|
+
def add(redis, key, queue)
|
21
20
|
redis.call("SADD", key, queue)
|
22
21
|
end
|
23
22
|
|
24
|
-
def
|
23
|
+
def remove(redis, key, queue)
|
25
24
|
redis.call("SREM", key, queue)
|
26
25
|
end
|
27
26
|
|
28
|
-
def
|
27
|
+
def list(redis, key)
|
29
28
|
# Cursor is not atomic, so there may be duplicates because of
|
30
29
|
# concurrent update operations
|
31
30
|
# See: https://redis.io/commands/scan/#scan-guarantees
|
@@ -13,30 +13,37 @@ module Sidekiq
|
|
13
13
|
|
14
14
|
if Runtime::SIDEKIQ_SEVEN
|
15
15
|
def queues_cmd
|
16
|
-
|
17
|
-
@
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
queues =
|
17
|
+
if @strictly_ordered_queues
|
18
|
+
@queues
|
19
|
+
else
|
20
|
+
permute = @queues.dup
|
21
|
+
permute.shuffle!
|
22
|
+
permute.uniq!
|
23
|
+
permute
|
24
|
+
end
|
25
|
+
|
26
|
+
excluding_paused(queues)
|
24
27
|
end
|
25
28
|
else
|
26
29
|
def queues_cmd
|
27
30
|
queues =
|
28
31
|
if @strictly_ordered_queues
|
29
|
-
@queues[0...-1]
|
32
|
+
@queues[0...-1]
|
30
33
|
else
|
31
|
-
permute =
|
34
|
+
permute = @queues.dup
|
32
35
|
permute.shuffle!
|
33
36
|
permute.uniq!
|
34
37
|
permute
|
35
38
|
end
|
36
39
|
|
37
|
-
queues << { timeout: Sidekiq::BasicFetch::TIMEOUT }
|
40
|
+
excluding_paused(queues) << { timeout: Sidekiq::BasicFetch::TIMEOUT }
|
38
41
|
end
|
39
42
|
end
|
43
|
+
|
44
|
+
def excluding_paused(queues)
|
45
|
+
queues - Pauzer.paused_queues.map { |name| "queue:#{name}" }
|
46
|
+
end
|
40
47
|
end
|
41
48
|
end
|
42
49
|
end
|
@@ -12,12 +12,10 @@ module Sidekiq
|
|
12
12
|
|
13
13
|
class Refresher < Concurrent::TimerTask; end
|
14
14
|
|
15
|
-
QUEUE_PREFIX = "queue:"
|
16
|
-
|
17
15
|
# @param config [Config]
|
18
16
|
def initialize(config)
|
19
17
|
@mutex = Mutex.new
|
20
|
-
@
|
18
|
+
@names = []
|
21
19
|
@redis_key = config.redis_key
|
22
20
|
@refresher = initialize_refresher(config.refresh_rate)
|
23
21
|
end
|
@@ -25,29 +23,29 @@ module Sidekiq
|
|
25
23
|
def each(&block)
|
26
24
|
return to_enum __method__ unless block
|
27
25
|
|
28
|
-
@mutex.synchronize { @
|
26
|
+
@mutex.synchronize { @names.dup }.each(&block)
|
29
27
|
|
30
28
|
self
|
31
29
|
end
|
32
30
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
Sidekiq.redis { |conn| Adapters[conn].pause!(conn, @redis_key, queue) }
|
31
|
+
# @param name [#to_s]
|
32
|
+
def pause!(name)
|
33
|
+
Sidekiq.redis { |conn| Adapters[conn].add(conn, @redis_key, name.to_s) }
|
37
34
|
|
38
35
|
refresh
|
39
36
|
end
|
40
37
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
Sidekiq.redis { |conn| Adapters[conn].unpause!(conn, @redis_key, queue) }
|
38
|
+
# @param name [#to_s]
|
39
|
+
def unpause!(name)
|
40
|
+
Sidekiq.redis { |conn| Adapters[conn].remove(conn, @redis_key, name.to_s) }
|
45
41
|
|
46
42
|
refresh
|
47
43
|
end
|
48
44
|
|
49
|
-
|
50
|
-
|
45
|
+
# @param name [#to_s]
|
46
|
+
# @return [Boolean]
|
47
|
+
def paused?(name)
|
48
|
+
include?(name.to_s)
|
51
49
|
end
|
52
50
|
|
53
51
|
def start_refresher
|
@@ -76,19 +74,13 @@ module Sidekiq
|
|
76
74
|
|
77
75
|
def refresh
|
78
76
|
@mutex.synchronize do
|
79
|
-
|
80
|
-
Adapters[conn].paused_queues(conn, @redis_key)
|
81
|
-
end
|
77
|
+
names = Sidekiq.redis { |conn| Adapters[conn].list(conn, @redis_key) }
|
82
78
|
|
83
|
-
@
|
79
|
+
@names.replace(names)
|
84
80
|
end
|
85
81
|
|
86
82
|
self
|
87
83
|
end
|
88
|
-
|
89
|
-
def normalize_queue_name(queue)
|
90
|
-
queue.to_s.dup.delete_prefix(QUEUE_PREFIX)
|
91
|
-
end
|
92
84
|
end
|
93
85
|
end
|
94
86
|
end
|
data/lib/sidekiq/pauzer.rb
CHANGED
@@ -35,13 +35,67 @@ module Sidekiq
|
|
35
35
|
class << self
|
36
36
|
extend Forwardable
|
37
37
|
|
38
|
-
|
38
|
+
# @!attribute [r] redis_key
|
39
|
+
# @see Config#redis_key
|
40
|
+
# @return [String]
|
39
41
|
def_delegators :@config, :redis_key
|
40
42
|
|
43
|
+
# @example
|
44
|
+
# Sidekiq::Pauzer.pause!("minor")
|
45
|
+
# Sidekiq::Pauzer.paused?("minor") # => true
|
46
|
+
#
|
47
|
+
# @param (see Queues#pause!)
|
48
|
+
# @return [void]
|
49
|
+
def pause!(name)
|
50
|
+
@queues.pause!(name)
|
51
|
+
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
|
55
|
+
# @example
|
56
|
+
# Sidekiq::Pauzer.pause!("minor")
|
57
|
+
# Sidekiq::Pauzer.paused?("minor") # => true
|
58
|
+
# Sidekiq::Pauzer.unpause!("minor")
|
59
|
+
# Sidekiq::Pauzer.paused?("minor") # => false
|
60
|
+
#
|
61
|
+
# @param (see Queues#unpause!)
|
62
|
+
# @return [void]
|
63
|
+
def unpause!(name)
|
64
|
+
@queues.unpause!(name)
|
65
|
+
|
66
|
+
nil
|
67
|
+
end
|
68
|
+
|
69
|
+
# @example
|
70
|
+
# Sidekiq::Pauzer.pause!("minor")
|
71
|
+
# Sidekiq::Pauzer.paused?("minor") # => true
|
72
|
+
# Sidekiq::Pauzer.paused?("threat") # => false
|
73
|
+
#
|
74
|
+
# @see Queues#paused?
|
75
|
+
def paused?(name)
|
76
|
+
@queues.paused?(name)
|
77
|
+
end
|
78
|
+
|
79
|
+
# @example
|
80
|
+
# Sidekiq::Pauzer.pause!("minor")
|
81
|
+
# Sidekiq::Pauzer.paused_queues # => ["minor"]
|
82
|
+
#
|
83
|
+
# @return [Array<String>]
|
41
84
|
def paused_queues
|
42
|
-
@queues.
|
85
|
+
@queues.to_a
|
43
86
|
end
|
44
87
|
|
88
|
+
# @deprecated Use {.paused_queues}
|
89
|
+
alias paused_queue_names paused_queues
|
90
|
+
|
91
|
+
# Yields `config` for a block.
|
92
|
+
#
|
93
|
+
# @example
|
94
|
+
# Sidekiq::Pauzer.configure do |config|
|
95
|
+
# config.refresh_rate = 42
|
96
|
+
# end
|
97
|
+
#
|
98
|
+
# @yieldparam config [Config]
|
45
99
|
def configure
|
46
100
|
MUTEX.synchronize do
|
47
101
|
config = @config.dup
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-pauzer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Zapparov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -66,9 +66,9 @@ licenses:
|
|
66
66
|
- MIT
|
67
67
|
metadata:
|
68
68
|
homepage_uri: https://gitlab.com/ixti/sidekiq-pauzer
|
69
|
-
source_code_uri: https://gitlab.com/ixti/sidekiq-pauzer/tree/
|
69
|
+
source_code_uri: https://gitlab.com/ixti/sidekiq-pauzer/tree/v2.1.0
|
70
70
|
bug_tracker_uri: https://gitlab.com/ixti/sidekiq-pauzer/issues
|
71
|
-
changelog_uri: https://gitlab.com/ixti/sidekiq-pauzer/blob/
|
71
|
+
changelog_uri: https://gitlab.com/ixti/sidekiq-pauzer/blob/v2.1.0/CHANGES.md
|
72
72
|
rubygems_mfa_required: 'true'
|
73
73
|
post_install_message:
|
74
74
|
rdoc_options: []
|