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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3fd06c20e80c3054e38f6a1e53154ba2dc039d9d866adc27408356cf22ac4566
4
- data.tar.gz: a2cf3bbb0255b83f5e31a9d73eec85c9d3c4cc448cf84bc2e227c60337d37446
3
+ metadata.gz: 7bfbbdbcf00da656eb48a8dccb0807b68e8554f6a02c6ed54e954f19d0ddd46b
4
+ data.tar.gz: 4887f3d8e032f2a48327e4e40ded771cf8552620f82e6b2744ce0625b0d89369
5
5
  SHA512:
6
- metadata.gz: bf1039b0984731d50e3719363aa877bb1d21a4f52fa8b4c1c1b654f4c63279f683b186e9311fbd4c358cbd418b7f4603bf66296ddb9234a087298170fc7d758f
7
- data.tar.gz: b87a05f362382c06ba9c985c24e9e2e6678fe977b10c1a2444ed41d68896be307de4b2df938b796ea4f84cad30ab047cc0f23a11ad7b9419d5e059edf658a6ae
6
+ metadata.gz: 73d2a4ae6200e308e83052947614759ea3db81bf22d481d67ae2d4c83d6531aa1c267f0662e8e231c0bad4e5091d6e99e568ae16e8919af016b55f742d4f243e
7
+ data.tar.gz: ca0824fa84c56ef904cac670fe5ed43d1f90701c6983ca0710cfa5d71cb01dd9a05ceeed45c8d98c9c32eb4a03192eae19120bf1fd7c7ac8e86f09baaa33bb99
data/README.adoc CHANGED
@@ -49,7 +49,7 @@ Those translates to:
49
49
 
50
50
  [source, ruby]
51
51
  ----
52
- Sidekiq::Pauzer.paused?("critical").paused? # => true|false
52
+ Sidekiq::Pauzer.paused?("critical") # => true|false
53
53
  Sidekiq::Pauzer.pause!("critical")
54
54
  Sidekiq::Pauzer.unpause!("critical")
55
55
  ----
@@ -13,15 +13,15 @@ module Sidekiq
13
13
  false
14
14
  end
15
15
 
16
- def pause!(redis, key, queue)
16
+ def add(redis, key, queue)
17
17
  redis.sadd(key, queue)
18
18
  end
19
19
 
20
- def unpause!(redis, key, queue)
20
+ def remove(redis, key, queue)
21
21
  redis.srem(key, queue)
22
22
  end
23
23
 
24
- def paused_queues(redis, key)
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 <= SIDEKIQ_VERSION
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 pause!(redis, key, queue)
19
+ def add(redis, key, queue)
21
20
  redis.call("SADD", key, queue)
22
21
  end
23
22
 
24
- def unpause!(redis, key, queue)
23
+ def remove(redis, key, queue)
25
24
  redis.call("SREM", key, queue)
26
25
  end
27
26
 
28
- def paused_queues(redis, key)
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
- if @strictly_ordered_queues
17
- @queues - Pauzer.paused_queues
18
- else
19
- permute = (@queues - Pauzer.paused_queues)
20
- permute.shuffle!
21
- permute.uniq!
22
- permute
23
- end
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] - Pauzer.paused_queues
32
+ @queues[0...-1]
30
33
  else
31
- permute = (@queues - Pauzer.paused_queues)
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
@@ -6,6 +6,7 @@ require "sidekiq/api"
6
6
  module Sidekiq
7
7
  module Pauzer
8
8
  module Patches
9
+ # @private
9
10
  module Queue
10
11
  def self.apply!
11
12
  Sidekiq::Queue.prepend(self)
@@ -8,6 +8,7 @@ require "sidekiq/web"
8
8
  module Sidekiq
9
9
  module Pauzer
10
10
  module Patches
11
+ # @private
11
12
  module WebAction
12
13
  PAUZER_QUEUES_TEMPLATE =
13
14
  ERB.new(File.read(File.expand_path("../../../../web/views/queues.erb", __dir__))).src
@@ -6,6 +6,7 @@ require "sidekiq/web"
6
6
  module Sidekiq
7
7
  module Pauzer
8
8
  module Patches
9
+ # @private
9
10
  module WebApplication
10
11
  class << self
11
12
  def apply!
@@ -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
- @queues = []
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 { @queues.dup }.each(&block)
26
+ @mutex.synchronize { @names.dup }.each(&block)
29
27
 
30
28
  self
31
29
  end
32
30
 
33
- def pause!(queue)
34
- queue = normalize_queue_name(queue)
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
- def unpause!(queue)
42
- queue = normalize_queue_name(queue)
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
- def paused?(queue)
50
- include?(normalize_queue_name(queue))
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
- paused_queues = Sidekiq.redis do |conn|
80
- Adapters[conn].paused_queues(conn, @redis_key)
81
- end
77
+ names = Sidekiq.redis { |conn| Adapters[conn].list(conn, @redis_key) }
82
78
 
83
- @queues.replace(paused_queues)
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sidekiq
4
4
  module Pauzer
5
- VERSION = "1.0.0"
5
+ VERSION = "2.1.0"
6
6
  end
7
7
  end
@@ -35,13 +35,67 @@ module Sidekiq
35
35
  class << self
36
36
  extend Forwardable
37
37
 
38
- def_delegators :@queues, :pause!, :unpause!, :paused?
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.map { |queue| "#{Queues::QUEUE_PREFIX}#{queue}" }
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.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-09 00:00:00.000000000 Z
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/v1.0.0
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/v1.0.0/CHANGES.md
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: []