sidekiq-pauzer 5.0.0 → 5.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: 64adf3a12da0acaeaffcb603aae15d37e3895822a01bd3128b82f16d429181f9
4
- data.tar.gz: c8246993271ccbe1723fe89e8e5955a80660a950f273d4b5b251763a6958c1b5
3
+ metadata.gz: c5f31ae5cfdfd5dd4e693e42c0bb82fbef4012cf9289772542f32131d996ecf7
4
+ data.tar.gz: 9bf1d72ce135955e7887b0926df8b83e6e3333e2c86f7ba1f7070c1277a4c6fd
5
5
  SHA512:
6
- metadata.gz: be9f0cb3175391264e3fb005a39fd4c17e9fa9a9374a2e667155e113b0c626a17f522b973162a6b4e3c37c84b886738c436666baf1c12691c6134d915d033d94
7
- data.tar.gz: 628d2cea3110e4bda2a61112bd529bb44513e2fd7cf9de1795a45c0236309666e6fbc7f2bcea3f05af0ac72855c1e5e5e2651371f7efafd92b87b3cbb6990500
6
+ metadata.gz: 3c7d00653876ac75e9cf299ad49152d8818380de5c18e670f023dfa5ffa07c9dd2b2755a8cfab71a9cb37e7b7d46d4e119653b314425ef8ffb57c1ffaa87414c
7
+ data.tar.gz: 89ab9cc7e4b0b90b4e3fa1b54b6a8e50577f52738faf0b96030edadc5fdddc1f6fd170b49aaf32be88a3538c31136404ee31576bf258ed2c7896584b189061cc
@@ -6,93 +6,54 @@ require "concurrent"
6
6
  module Sidekiq
7
7
  module Pauzer
8
8
  # @api internal
9
+ # Eventually consistent list of paused queues. Used by Sidekiq fetchers to
10
+ # avoid hitting Redis on every fetch call.
9
11
  class Queues
10
- extend Forwardable
11
12
  include Enumerable
12
13
 
13
- # @!attribute [r] refresh_rate
14
- # @see (Config#refresh_rate)
15
- def_delegators :@config, :refresh_rate
16
-
17
- # @param config [Config]
18
- def initialize(config)
19
- @config = config
20
- @names = [].freeze
21
- @names_mutex = Mutex.new
22
- @refresher = nil
23
- @refresher_mutex = Mutex.new
14
+ # @param refresh_rate [Float]
15
+ # @param repository [Repository]
16
+ def initialize(refresh_rate, repository:)
17
+ @names = [].freeze
18
+ @refresher = Concurrent::TimerTask.new(execution_interval: refresh_rate, run_now: true) do
19
+ @names = repository.to_a.freeze
20
+ end
24
21
  end
25
22
 
23
+ # @overload each
24
+ # @return [Enumerator<String>]
25
+ #
26
+ # @overload each(&block)
27
+ # For a block { |queue_name| ... }
28
+ # @yieldparam queue_name [String]
29
+ # @return [self]
26
30
  def each(&block)
27
31
  return to_enum __method__ unless block
28
32
 
29
33
  start_refresher unless refresher_running?
30
- @names_mutex.synchronize { @names.dup }.each(&block)
31
-
32
- self
33
- end
34
-
35
- # @param name [#to_s]
36
- # @return [Queues] self
37
- def pause!(name)
38
- redis_call("SADD", Pauzer::REDIS_KEY, name.to_s)
39
- refresh
40
- self
41
- end
34
+ @names.each(&block)
42
35
 
43
- # @param name [#to_s]
44
- # @return [Queues] self
45
- def unpause!(name)
46
- redis_call("SREM", Pauzer::REDIS_KEY, name.to_s)
47
- refresh
48
36
  self
49
37
  end
50
38
 
51
- # @param name [#to_s]
52
- # @return [Boolean]
53
- def paused?(name)
54
- include?(name.to_s)
55
- end
56
-
39
+ # Starts paused queues list async poller.
40
+ #
41
+ # @return [self]
57
42
  def start_refresher
58
- @refresher_mutex.synchronize do
59
- @refresher&.shutdown
60
- @refresher = Concurrent::TimerTask.execute(execution_interval: refresh_rate, run_now: true) { refresh }
61
- end
62
-
43
+ @refresher.execute
63
44
  self
64
45
  end
65
46
 
47
+ # Stops paused queues list async poller.
48
+ #
49
+ # @return [self]
66
50
  def stop_refresher
67
- @refresher_mutex.synchronize do
68
- @refresher&.shutdown
69
- @refresher = nil
70
- end
71
-
51
+ @refresher.shutdown
72
52
  self
73
53
  end
74
54
 
75
55
  def refresher_running?
76
- @refresher_mutex.synchronize do
77
- @refresher&.running? || false
78
- end
79
- end
80
-
81
- private
82
-
83
- # @return [nil]
84
- def refresh
85
- names = redis_call("SMEMBERS", Pauzer::REDIS_KEY).to_a
86
-
87
- @names_mutex.synchronize do
88
- @names = names.each(&:freeze).freeze
89
- end
90
-
91
- nil
92
- end
93
-
94
- def redis_call(...)
95
- Sidekiq.redis { |conn| conn.call(...) }
56
+ @refresher.running?
96
57
  end
97
58
  end
98
59
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sidekiq
4
+ module Pauzer
5
+ class Repository
6
+ include Enumerable
7
+
8
+ REDIS_KEY = "sidekiq-pauzer"
9
+
10
+ # @overload each
11
+ # @return [Enumerator<String>]
12
+ #
13
+ # @overload each(&block)
14
+ # For a block { |queue_name| ... }
15
+ # @yieldparam queue_name [String]
16
+ # @return [self]
17
+ def each
18
+ return to_enum __method__ unless block_given?
19
+
20
+ redis_call("SMEMBERS", REDIS_KEY).each { yield _1.freeze }
21
+
22
+ self
23
+ end
24
+
25
+ # @param queue_name [#to_s]
26
+ # @return [void]
27
+ def add(queue_name)
28
+ redis_call("SADD", REDIS_KEY, queue_name.to_s)
29
+ nil
30
+ end
31
+
32
+ # @param queue_name [#to_s]
33
+ # @return [void]
34
+ def delete(queue_name)
35
+ redis_call("SREM", REDIS_KEY, queue_name.to_s)
36
+ nil
37
+ end
38
+
39
+ # @param name [#to_s]
40
+ # @return [void]
41
+ def include?(queue_name)
42
+ redis_call("SISMEMBER", REDIS_KEY, queue_name.to_s).positive?
43
+ end
44
+
45
+ private
46
+
47
+ def redis_call(...)
48
+ Sidekiq.redis { _1.call(...) }
49
+ end
50
+ end
51
+ end
52
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sidekiq
4
4
  module Pauzer
5
- VERSION = "5.0.0"
5
+ VERSION = "5.1.0"
6
6
  end
7
7
  end
@@ -1,52 +1,51 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "forwardable"
4
3
  require "sidekiq"
5
4
  require "sidekiq/api"
6
5
 
7
- require_relative "./pauzer/config"
8
- require_relative "./pauzer/patches/basic_fetch"
9
- require_relative "./pauzer/patches/queue"
10
- require_relative "./pauzer/queues"
11
- require_relative "./pauzer/version"
12
-
13
6
  begin
7
+ # :nocov:
14
8
  require "sidekiq-ent/version"
9
+ raise "sidekiq-pauzer is incompatible with Sidekiq Enterprise"
10
+ # :nocov:
15
11
  rescue LoadError
16
12
  # All good - no compatibility issues
17
13
  end
18
14
 
19
15
  begin
16
+ # :nocov:
20
17
  require "sidekiq/pro/version"
18
+ raise "sidekiq-pauzer is incompatible with Sidekiq Pro"
19
+ # :nocov:
21
20
  rescue LoadError
22
21
  # All good - no compatibility issues
23
22
  end
24
23
 
25
- raise "sidekiq-pauzer is incompatible with Sidekiq Pro" if Sidekiq.pro?
26
- raise "sidekiq-pauzer is incompatible with Sidekiq Enterprise" if Sidekiq.ent?
24
+ require_relative "./pauzer/config"
25
+ require_relative "./pauzer/patches/basic_fetch"
26
+ require_relative "./pauzer/patches/queue"
27
+ require_relative "./pauzer/queues"
28
+ require_relative "./pauzer/repository"
29
+ require_relative "./pauzer/version"
27
30
 
28
31
  module Sidekiq
29
32
  module Pauzer
30
- REDIS_KEY = "sidekiq-pauzer"
31
-
32
33
  MUTEX = Mutex.new
33
34
  private_constant :MUTEX
34
35
 
35
- @config = Config.new.freeze
36
- @queues = Queues.new(@config)
36
+ @config = Config.new.freeze
37
+ @repository = Repository.new
38
+ @queues = Queues.new(@config.refresh_rate, repository: @repository)
37
39
 
38
40
  class << self
39
- extend Forwardable
40
-
41
41
  # @example
42
42
  # Sidekiq::Pauzer.pause!("minor")
43
43
  # Sidekiq::Pauzer.paused?("minor") # => true
44
44
  #
45
- # @param (see Queues#pause!)
45
+ # @param (see Repository#add)
46
46
  # @return [void]
47
- def pause!(name)
48
- @queues.pause!(name)
49
-
47
+ def pause!(queue_name)
48
+ @repository.add(queue_name)
50
49
  nil
51
50
  end
52
51
 
@@ -56,11 +55,10 @@ module Sidekiq
56
55
  # Sidekiq::Pauzer.unpause!("minor")
57
56
  # Sidekiq::Pauzer.paused?("minor") # => false
58
57
  #
59
- # @param (see Queues#unpause!)
58
+ # @param (see Repository#delete)
60
59
  # @return [void]
61
- def unpause!(name)
62
- @queues.unpause!(name)
63
-
60
+ def unpause!(queue_name)
61
+ @repository.delete(queue_name)
64
62
  nil
65
63
  end
66
64
 
@@ -69,11 +67,13 @@ module Sidekiq
69
67
  # Sidekiq::Pauzer.paused?("minor") # => true
70
68
  # Sidekiq::Pauzer.paused?("threat") # => false
71
69
  #
72
- # @see Queues#paused?
73
- def paused?(name)
74
- @queues.paused?(name)
70
+ # @return (see Repository#include?)
71
+ def paused?(queue_name)
72
+ @repository.include?(queue_name)
75
73
  end
76
74
 
75
+ # Eventually consistent list of paused queues.
76
+ #
77
77
  # @example
78
78
  # Sidekiq::Pauzer.pause!("minor")
79
79
  # Sidekiq::Pauzer.paused_queues # => ["minor"]
@@ -121,7 +121,7 @@ module Sidekiq
121
121
 
122
122
  def reinit_queues
123
123
  @queues.stop_refresher
124
- @queues = Queues.new(@config)
124
+ @queues = Queues.new(@config.refresh_rate, repository: @repository)
125
125
  end
126
126
  end
127
127
  end
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: 5.0.0
4
+ version: 5.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-12-09 00:00:00.000000000 Z
11
+ date: 2023-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -55,6 +55,7 @@ files:
55
55
  - lib/sidekiq/pauzer/patches/web_action.rb
56
56
  - lib/sidekiq/pauzer/patches/web_application.rb
57
57
  - lib/sidekiq/pauzer/queues.rb
58
+ - lib/sidekiq/pauzer/repository.rb
58
59
  - lib/sidekiq/pauzer/version.rb
59
60
  - lib/sidekiq/pauzer/web.rb
60
61
  - web/views/queues.erb
@@ -63,9 +64,9 @@ licenses:
63
64
  - MIT
64
65
  metadata:
65
66
  homepage_uri: https://github.com/ixti/sidekiq-pauzer
66
- source_code_uri: https://github.com/ixti/sidekiq-pauzer/tree/v5.0.0
67
+ source_code_uri: https://github.com/ixti/sidekiq-pauzer/tree/v5.1.0
67
68
  bug_tracker_uri: https://github.com/ixti/sidekiq-pauzer/issues
68
- changelog_uri: https://github.com/ixti/sidekiq-pauzer/blob/v5.0.0/CHANGES.md
69
+ changelog_uri: https://github.com/ixti/sidekiq-pauzer/blob/v5.1.0/CHANGES.md
69
70
  rubygems_mfa_required: 'true'
70
71
  post_install_message:
71
72
  rdoc_options: []