sidekiq-pauzer 4.1.0 → 4.2.1

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: c4907f516e85f120c7f3bab0c18d1832995d3b31cfd788fb4f3bed2258c9cf0b
4
- data.tar.gz: f697759608b23f58eec74cae99d0c5ec6773f1f7304b87e5f34d4e3dd437f0a3
3
+ metadata.gz: e7ba4ea9d9b061ee7d506874e2f6dd7e3128d912f194df3f7eea66e134ee5342
4
+ data.tar.gz: e7c7a9140a6fb5e450b13ab2f97740908036d4cca4d28a1dbb40cea1210ce7b9
5
5
  SHA512:
6
- metadata.gz: a89c0004ea1ef1bd6684e1778194a3ec63be336df0a46a19870c3a3cd97e12d9a24e00c448562fd1e095de0c1ad94bbce2a299d640e2fcad16a6fddac8077463
7
- data.tar.gz: a13a58fc1cd1fdadfa91ad211c0095f85e7b48be126c73b169cf7fa645fd6866df81ea5be845097f4ece5acdbd9c910ed49af95b113e59b6a428dcb6f9783e32
6
+ metadata.gz: 1abbf6aa4603205e520b197f93b08f6ad485a285c33dd64bb1b7eb01b8e54f80f0622a816d2fabf43b369c16abdf73beda3b220446ea023f9fe197bd11eeb7f0
7
+ data.tar.gz: f70b7cff1ef0955a932c0df368425213524bcf286d6ec4bc9803cf2486c246b835d2c6ae5c3c1f118b7c7adcc09e929a124295218183e45daf266eebca779535
data/README.adoc CHANGED
@@ -30,6 +30,15 @@ Sidekiq::Pauzer.configure do |config|
30
30
  end
31
31
  ----
32
32
 
33
+ When running in forked environment (e.g., Puma web server), you also need to
34
+ call `Sidekiq::Pauzer.startup` on fork:
35
+
36
+ [source, ruby]
37
+ ----
38
+ # file: config/puma.rb
39
+ on_worker_boot { Sidekiq::Pauzer.startup }
40
+ ----
41
+
33
42
  === API
34
43
 
35
44
  This gem enhances Sidekiq's Queue API with:
@@ -1,41 +1,55 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "forwardable"
3
4
  require "concurrent"
4
5
 
5
6
  module Sidekiq
6
7
  module Pauzer
7
8
  # @api internal
8
9
  class Queues
10
+ extend Forwardable
9
11
  include Enumerable
10
12
 
11
- class Refresher < Concurrent::TimerTask; end
13
+ # @!attribute [r] redis_key
14
+ # @see (Config#redis_key)
15
+ def_delegators :@config, :redis_key
16
+
17
+ # @!attribute [r] refresh_rate
18
+ # @see (Config#refresh_rate)
19
+ def_delegators :@config, :refresh_rate
12
20
 
13
21
  # @param config [Config]
14
22
  def initialize(config)
15
- @mutex = Mutex.new
16
- @names = [].freeze
17
- @redis_key = config.redis_key
18
- @refresher = initialize_refresher(config.refresh_rate)
23
+ @config = config
24
+ @names = [].freeze
25
+ @names_mutex = Mutex.new
26
+ @refresher = nil
27
+ @refresher_mutex = Mutex.new
19
28
  end
20
29
 
21
30
  def each(&block)
22
31
  return to_enum __method__ unless block
23
32
 
24
- @names.each(&block)
33
+ start_refresher unless refresher_running?
34
+ @names_mutex.synchronize { @names.dup }.each(&block)
25
35
 
26
36
  self
27
37
  end
28
38
 
29
39
  # @param name [#to_s]
40
+ # @return [Queues] self
30
41
  def pause!(name)
31
- Sidekiq.redis { |conn| conn.call("SADD", @redis_key, name.to_s) }
42
+ redis_call("SADD", redis_key, name.to_s)
32
43
  refresh
44
+ self
33
45
  end
34
46
 
35
47
  # @param name [#to_s]
48
+ # @return [Queues] self
36
49
  def unpause!(name)
37
- Sidekiq.redis { |conn| conn.call("SREM", @redis_key, name.to_s) }
50
+ redis_call("SREM", redis_key, name.to_s)
38
51
  refresh
52
+ self
39
53
  end
40
54
 
41
55
  # @param name [#to_s]
@@ -45,35 +59,44 @@ module Sidekiq
45
59
  end
46
60
 
47
61
  def start_refresher
48
- @refresher.execute
62
+ @refresher_mutex.synchronize do
63
+ @refresher&.shutdown
64
+ @refresher = Concurrent::TimerTask.execute(execution_interval: refresh_rate, run_now: true) { refresh }
65
+ end
49
66
 
50
67
  self
51
68
  end
52
69
 
53
70
  def stop_refresher
54
- @refresher.shutdown
71
+ @refresher_mutex.synchronize do
72
+ @refresher&.shutdown
73
+ @refresher = nil
74
+ end
55
75
 
56
76
  self
57
77
  end
58
78
 
59
79
  def refresher_running?
60
- @refresher.running?
80
+ @refresher_mutex.synchronize do
81
+ @refresher&.running? || false
82
+ end
61
83
  end
62
84
 
63
85
  private
64
86
 
65
- def initialize_refresher(refresh_rate)
66
- Refresher.new(execution_interval: refresh_rate, run_now: true) do
67
- refresh
68
- end
69
- end
70
-
87
+ # @return [nil]
71
88
  def refresh
72
- names = Sidekiq.redis { |conn| conn.call("SMEMBERS", @redis_key).to_a }
89
+ names = redis_call("SMEMBERS", redis_key).to_a
90
+
91
+ @names_mutex.synchronize do
92
+ @names = names.each(&:freeze).freeze
93
+ end
73
94
 
74
- @mutex.synchronize { @names = names.each(&:freeze).freeze }
95
+ nil
96
+ end
75
97
 
76
- self
98
+ def redis_call(...)
99
+ Sidekiq.redis { |conn| conn.call(...) }
77
100
  end
78
101
  end
79
102
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sidekiq
4
4
  module Pauzer
5
- VERSION = "4.1.0"
5
+ VERSION = "4.2.1"
6
6
  end
7
7
  end
@@ -108,7 +108,7 @@ module Sidekiq
108
108
  end
109
109
 
110
110
  def startup
111
- MUTEX.synchronize { @queues.start_refresher }
111
+ MUTEX.synchronize { reinit_queues.start_refresher }
112
112
 
113
113
  self
114
114
  end
@@ -122,10 +122,8 @@ module Sidekiq
122
122
  private
123
123
 
124
124
  def reinit_queues
125
- start_refresher = @queues.refresher_running?
126
125
  @queues.stop_refresher
127
126
  @queues = Queues.new(@config)
128
- @queues.start_refresher if start_refresher
129
127
  end
130
128
  end
131
129
  end
data/web/views/queues.erb CHANGED
@@ -1,3 +1,5 @@
1
+ <!-- sidekiq-pauzer <%= Sidekiq::Pauzer::VERSION %> -->
2
+
1
3
  <div class="header-container">
2
4
  <h1><%= t('Queues') %></h1>
3
5
  </div>
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: 4.1.0
4
+ version: 4.2.1
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-11-22 00:00:00.000000000 Z
11
+ date: 2023-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -58,14 +58,14 @@ files:
58
58
  - lib/sidekiq/pauzer/version.rb
59
59
  - lib/sidekiq/pauzer/web.rb
60
60
  - web/views/queues.erb
61
- homepage: https://gitlab.com/ixti/sidekiq-pauzer
61
+ homepage: https://github.com/ixti/sidekiq-pauzer
62
62
  licenses:
63
63
  - MIT
64
64
  metadata:
65
- homepage_uri: https://gitlab.com/ixti/sidekiq-pauzer
66
- source_code_uri: https://gitlab.com/ixti/sidekiq-pauzer/tree/v4.1.0
67
- bug_tracker_uri: https://gitlab.com/ixti/sidekiq-pauzer/issues
68
- changelog_uri: https://gitlab.com/ixti/sidekiq-pauzer/blob/v4.1.0/CHANGES.md
65
+ homepage_uri: https://github.com/ixti/sidekiq-pauzer
66
+ source_code_uri: https://github.com/ixti/sidekiq-pauzer/tree/v4.2.1
67
+ bug_tracker_uri: https://github.com/ixti/sidekiq-pauzer/issues
68
+ changelog_uri: https://github.com/ixti/sidekiq-pauzer/blob/v4.2.1/CHANGES.md
69
69
  rubygems_mfa_required: 'true'
70
70
  post_install_message:
71
71
  rdoc_options: []