sidekiq-pauzer 4.1.0 → 4.2.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: c4907f516e85f120c7f3bab0c18d1832995d3b31cfd788fb4f3bed2258c9cf0b
4
- data.tar.gz: f697759608b23f58eec74cae99d0c5ec6773f1f7304b87e5f34d4e3dd437f0a3
3
+ metadata.gz: e0cfd697bb2a9f06be2bd59ef44bbb4ffc6f5bcf073d67117e5f4df50f04774c
4
+ data.tar.gz: 1b2712b8d2bec0253e32386d966798b76e7d33f2590833761c3c3d231631bbb6
5
5
  SHA512:
6
- metadata.gz: a89c0004ea1ef1bd6684e1778194a3ec63be336df0a46a19870c3a3cd97e12d9a24e00c448562fd1e095de0c1ad94bbce2a299d640e2fcad16a6fddac8077463
7
- data.tar.gz: a13a58fc1cd1fdadfa91ad211c0095f85e7b48be126c73b169cf7fa645fd6866df81ea5be845097f4ece5acdbd9c910ed49af95b113e59b6a428dcb6f9783e32
6
+ metadata.gz: 38beb5711a6a1eef4aa51cc538642e4de4dd7c5a51a12c8bd2084430034da09b4b0c6fea78a9da14192372319735fd53ce76ed92a47b9b4a4957ff8112df0fc7
7
+ data.tar.gz: 052b517478b5cae0f700cf8f94f044c19398519f5d65c285290e08f6117d70a1fb80ec8a984b0d78bfb1a4c9670d139d9d78e431fc54a70e8a74f08d4238c22d
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,40 +1,50 @@
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
+ @names = [].freeze
24
+ @config = config
25
+ @init_mutex = Mutex.new
26
+ @poll_mutex = Mutex.new
27
+ @refresher = nil
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
+ @poll_mutex.synchronize { @names.dup }.each(&block)
25
35
 
26
36
  self
27
37
  end
28
38
 
29
39
  # @param name [#to_s]
30
40
  def pause!(name)
31
- Sidekiq.redis { |conn| conn.call("SADD", @redis_key, name.to_s) }
41
+ Sidekiq.redis { |conn| conn.call("SADD", redis_key, name.to_s) }
32
42
  refresh
33
43
  end
34
44
 
35
45
  # @param name [#to_s]
36
46
  def unpause!(name)
37
- Sidekiq.redis { |conn| conn.call("SREM", @redis_key, name.to_s) }
47
+ Sidekiq.redis { |conn| conn.call("SREM", redis_key, name.to_s) }
38
48
  refresh
39
49
  end
40
50
 
@@ -45,33 +55,36 @@ module Sidekiq
45
55
  end
46
56
 
47
57
  def start_refresher
48
- @refresher.execute
58
+ @init_mutex.synchronize do
59
+ @refresher ||= Concurrent::TimerTask.new(execution_interval: refresh_rate, run_now: true) do
60
+ refresh
61
+ end
62
+
63
+ @refresher.execute
64
+ end
49
65
 
50
66
  self
51
67
  end
52
68
 
53
69
  def stop_refresher
54
- @refresher.shutdown
70
+ @init_mutex.synchronize do
71
+ @refresher&.shutdown
72
+ @refresher = nil
73
+ end
55
74
 
56
75
  self
57
76
  end
58
77
 
59
78
  def refresher_running?
60
- @refresher.running?
79
+ @init_mutex.synchronize { @refresher&.running? || false }
61
80
  end
62
81
 
63
82
  private
64
83
 
65
- def initialize_refresher(refresh_rate)
66
- Refresher.new(execution_interval: refresh_rate, run_now: true) do
67
- refresh
68
- end
69
- end
70
-
71
84
  def refresh
72
- names = Sidekiq.redis { |conn| conn.call("SMEMBERS", @redis_key).to_a }
85
+ names = Sidekiq.redis { |conn| conn.call("SMEMBERS", redis_key).to_a }
73
86
 
74
- @mutex.synchronize { @names = names.each(&:freeze).freeze }
87
+ @poll_mutex.synchronize { @names = names.each(&:freeze).freeze }
75
88
 
76
89
  self
77
90
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sidekiq
4
4
  module Pauzer
5
- VERSION = "4.1.0"
5
+ VERSION = "4.2.0"
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.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-11-22 00:00:00.000000000 Z
11
+ date: 2023-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -63,9 +63,9 @@ licenses:
63
63
  - MIT
64
64
  metadata:
65
65
  homepage_uri: https://gitlab.com/ixti/sidekiq-pauzer
66
- source_code_uri: https://gitlab.com/ixti/sidekiq-pauzer/tree/v4.1.0
66
+ source_code_uri: https://gitlab.com/ixti/sidekiq-pauzer/tree/v4.2.0
67
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
68
+ changelog_uri: https://gitlab.com/ixti/sidekiq-pauzer/blob/v4.2.0/CHANGES.md
69
69
  rubygems_mfa_required: 'true'
70
70
  post_install_message:
71
71
  rdoc_options: []