sidekiq-pauzer 1.0.0.alpha → 1.0.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: b38aee70ca050a4c5c0f8c41d81bae5b755bb4a73fd1b5ddb7b365fb61ba3f40
4
- data.tar.gz: e233b4b60fc065a12c29f809ad196f763f05a54d7bec640c338dce6ec2c62984
3
+ metadata.gz: 3fd06c20e80c3054e38f6a1e53154ba2dc039d9d866adc27408356cf22ac4566
4
+ data.tar.gz: a2cf3bbb0255b83f5e31a9d73eec85c9d3c4cc448cf84bc2e227c60337d37446
5
5
  SHA512:
6
- metadata.gz: 8e106b6c3e162eafddf56da121c6d3af3319928a145c1991f9c09ceeb54751eb68a15f716731e5bf2feb15fd785a7062ce19db5523a79b8a3be2e1889af39c94
7
- data.tar.gz: 1db224ec249b5729e903a0ad8fc9f58235e8a39c5bc39f00a2e11a426c3a0ec20fb216faa5bf144ef20bbfa93f4dc94d8599546ab46052724142a89420e29a07
6
+ metadata.gz: bf1039b0984731d50e3719363aa877bb1d21a4f52fa8b4c1c1b654f4c63279f683b186e9311fbd4c358cbd418b7f4603bf66296ddb9234a087298170fc7d758f
7
+ data.tar.gz: b87a05f362382c06ba9c985c24e9e2e6678fe977b10c1a2444ed41d68896be307de4b2df938b796ea4f84cad30ab047cc0f23a11ad7b9419d5e059edf658a6ae
data/README.adoc CHANGED
@@ -34,6 +34,25 @@ Sidekiq.configure_server do |config|
34
34
  end
35
35
  ----
36
36
 
37
+ === API
38
+
39
+ This gem enhances Sidekiq's Queue API with:
40
+
41
+ [source, ruby]
42
+ ----
43
+ Sidekiq::Queue.new("critical").paused? # => true|false
44
+ Sidekiq::Queue.new("critical").pause!
45
+ Sidekiq::Queue.new("critical").unpause!
46
+ ----
47
+
48
+ Those translates to:
49
+
50
+ [source, ruby]
51
+ ----
52
+ Sidekiq::Pauzer.paused?("critical").paused? # => true|false
53
+ Sidekiq::Pauzer.pause!("critical")
54
+ Sidekiq::Pauzer.unpause!("critical")
55
+ ----
37
56
 
38
57
  === Adding Pause/Resume Button to the Queues Tab
39
58
 
@@ -47,7 +66,39 @@ require "sidekiq/pauzer/web"
47
66
  ----
48
67
 
49
68
  NOTE: If you are using custom Sidekiq views path, then you will need to call
50
- (after requiring `sidekiq/pauzer/web`): `Sidekiq::Pauzer.unpatch_views!`.
69
+ (after requiring `sidekiq/pauzer/web`): `Sidekiq::Pauzer::Web.unpatch_views!`.
70
+
71
+
72
+ == Supported Ruby Versions
73
+
74
+ This library aims to support and is tested against the following Ruby versions:
75
+
76
+ * Ruby 2.7.x
77
+ * Ruby 3.0.x
78
+ * Ruby 3.1.x
79
+ * Ruby 3.2.x
80
+
81
+ If something doesn't work on one of these versions, it's a bug.
82
+
83
+ This library may inadvertently work (or seem to work) on other Ruby versions,
84
+ however support will only be provided for the versions listed above.
85
+
86
+ If you would like this library to support another Ruby version or
87
+ implementation, you may volunteer to be a maintainer. Being a maintainer
88
+ entails making sure all tests run and pass on that implementation. When
89
+ something breaks on your implementation, you will be responsible for providing
90
+ patches in a timely fashion. If critical issues for a particular implementation
91
+ exist at the time of a major release, support for that Ruby version may be
92
+ dropped.
93
+
94
+
95
+ == Supported Sidekiq Versions
96
+
97
+ This library aims to support and work with following Sidekiq versions:
98
+
99
+ * Sidekiq 6.5.x
100
+ * Sidekiq 7.0.x
101
+ * Sidekiq 7.1.x
51
102
 
52
103
 
53
104
  == Development
@@ -3,13 +3,15 @@
3
3
  require "sidekiq"
4
4
  require "sidekiq/fetch"
5
5
 
6
+ require_relative "./runtime"
7
+
6
8
  module Sidekiq
7
9
  module Pauzer
8
10
  # Default Sidekiq's BasicFetch infused with Pauzer
9
11
  class BasicFetch < Sidekiq::BasicFetch
10
12
  private
11
13
 
12
- if Gem::Version.new("7.0.0") <= Gem::Version.new(Sidekiq::VERSION)
14
+ if Runtime::SIDEKIQ_SEVEN
13
15
  def queues_cmd
14
16
  if @strictly_ordered_queues
15
17
  @queues - Pauzer.paused_queues
@@ -22,16 +24,17 @@ module Sidekiq
22
24
  end
23
25
  else
24
26
  def queues_cmd
25
- if @strictly_ordered_queues
26
- *queues, timeout = @queues
27
+ queues =
28
+ if @strictly_ordered_queues
29
+ @queues[0...-1] - Pauzer.paused_queues
30
+ else
31
+ permute = (@queues - Pauzer.paused_queues)
32
+ permute.shuffle!
33
+ permute.uniq!
34
+ permute
35
+ end
27
36
 
28
- (queues - Pauzer.paused_queues) << timeout
29
- else
30
- permute = (@queues - Pauzer.paused_queues)
31
- permute.shuffle!
32
- permute.uniq!
33
- permute << { timeout: Sidekiq::BasicFetch::TIMEOUT }
34
- end
37
+ queues << { timeout: Sidekiq::BasicFetch::TIMEOUT }
35
38
  end
36
39
  end
37
40
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sidekiq"
4
+ require "sidekiq/api"
5
+
6
+ module Sidekiq
7
+ module Pauzer
8
+ module Patches
9
+ module Queue
10
+ def self.apply!
11
+ Sidekiq::Queue.prepend(self)
12
+ end
13
+
14
+ def paused?
15
+ Pauzer.paused?(name)
16
+ end
17
+
18
+ def pause!
19
+ Pauzer.pause!(name)
20
+ nil
21
+ end
22
+
23
+ def unpause!
24
+ Pauzer.unpause!(name)
25
+ nil
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "erb"
4
+
5
+ require "sidekiq"
6
+ require "sidekiq/web"
7
+
8
+ module Sidekiq
9
+ module Pauzer
10
+ module Patches
11
+ module WebAction
12
+ PAUZER_QUEUES_TEMPLATE =
13
+ ERB.new(File.read(File.expand_path("../../../../web/views/queues.erb", __dir__))).src
14
+
15
+ class << self
16
+ def apply!
17
+ revert!
18
+
19
+ Sidekiq::WebAction.class_eval <<-RUBY, __FILE__, __LINE__ + 1 # rubocop:disable Style/DocumentDynamicEvalDefinition
20
+ def _erb_queues
21
+ #{PAUZER_QUEUES_TEMPLATE}
22
+ end
23
+ RUBY
24
+ end
25
+
26
+ def revert!
27
+ Sidekiq::WebAction.remove_method(:_erb_queues) if Sidekiq::WebAction.method_defined?(:_erb_queues)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sidekiq"
4
+ require "sidekiq/web"
5
+
6
+ module Sidekiq
7
+ module Pauzer
8
+ module Patches
9
+ module WebApplication
10
+ class << self
11
+ def apply!
12
+ remove_theirs_queue_update_route
13
+ register_ours_queue_update_route
14
+ end
15
+
16
+ private
17
+
18
+ def remove_theirs_queue_update_route
19
+ Sidekiq::WebApplication
20
+ .instance_variable_get(:@routes)
21
+ .fetch(Sidekiq::WebRouter::POST)
22
+ .delete_if { |route| route.pattern == "/queues/:name" }
23
+ end
24
+
25
+ def register_ours_queue_update_route # rubocop:disable Metrics/MethodLength
26
+ Sidekiq::WebApplication.class_exec do
27
+ post "/queues/:name" do
28
+ queue = Sidekiq::Queue.new(route_params[:name])
29
+
30
+ if params["pause"]
31
+ queue.pause!
32
+ elsif params["unpause"]
33
+ queue.unpause!
34
+ else
35
+ queue.clear
36
+ end
37
+
38
+ redirect "#{root_path}queues"
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -52,12 +52,14 @@ module Sidekiq
52
52
 
53
53
  def start_refresher
54
54
  @refresher.execute
55
- nil
55
+
56
+ self
56
57
  end
57
58
 
58
59
  def stop_refresher
59
60
  @refresher.shutdown
60
- nil
61
+
62
+ self
61
63
  end
62
64
 
63
65
  def refresher_running?
@@ -85,7 +87,7 @@ module Sidekiq
85
87
  end
86
88
 
87
89
  def normalize_queue_name(queue)
88
- queue.dup.delete_prefix(QUEUE_PREFIX)
90
+ queue.to_s.dup.delete_prefix(QUEUE_PREFIX)
89
91
  end
90
92
  end
91
93
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sidekiq"
4
+
5
+ module Sidekiq
6
+ module Pauzer
7
+ module Runtime
8
+ SIDEKIQ_SEVEN = Gem::Version.new("7.0.0") <= Gem::Version.new(Sidekiq::VERSION)
9
+ end
10
+ end
11
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sidekiq
4
4
  module Pauzer
5
- VERSION = "1.0.0.alpha"
5
+ VERSION = "1.0.0"
6
6
  end
7
7
  end
@@ -1,46 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "erb"
4
- require "sidekiq"
5
- require "sidekiq/web"
6
-
7
- require_relative "../pauzer"
3
+ require_relative "./patches/web_action"
4
+ require_relative "./patches/web_application"
8
5
 
9
6
  module Sidekiq
10
7
  module Pauzer
11
- def self.unpatch_views!
12
- WebAction.remove_method(:_erb_queues)
13
- end
14
- end
15
-
16
- class WebApplication
17
- @routes[Sidekiq::WebRouter::POST].delete_if do |web_route|
18
- web_route.pattern == "/queues/:name"
19
- end
20
-
21
- post "/queues/:name" do
22
- queue = Sidekiq::Queue.new(route_params[:name])
23
-
24
- if params["pause"]
25
- queue.pause!
26
- elsif params["unpause"]
27
- queue.unpause!
28
- else
29
- queue.clear
8
+ module Web
9
+ def self.unpatch_views!
10
+ Patches::WebAction.revert!
30
11
  end
31
-
32
- redirect "#{root_path}queues"
33
12
  end
34
13
  end
35
-
36
- class WebAction
37
- PAUZER_QUEUES_TEMPLATE =
38
- ERB.new(File.read(File.expand_path("../../../web/views/queues.erb", __dir__))).src
39
-
40
- class_eval <<-RUBY, __FILE__, __LINE__ + 1 # rubocop:disable Style/DocumentDynamicEvalDefinition
41
- def _erb_queues
42
- #{PAUZER_QUEUES_TEMPLATE}
43
- end
44
- RUBY
45
- end
46
14
  end
15
+
16
+ Sidekiq::Pauzer::Patches::WebAction.apply!
17
+ Sidekiq::Pauzer::Patches::WebApplication.apply!
@@ -6,6 +6,7 @@ require "sidekiq/api"
6
6
 
7
7
  require_relative "./pauzer/basic_fetch"
8
8
  require_relative "./pauzer/config"
9
+ require_relative "./pauzer/patches/queue"
9
10
  require_relative "./pauzer/queues"
10
11
  require_relative "./pauzer/version"
11
12
 
@@ -28,13 +29,14 @@ module Sidekiq
28
29
  module Pauzer
29
30
  MUTEX = Mutex.new
30
31
 
31
- @config = Config.new
32
+ @config = Config.new.freeze
32
33
  @queues = Queues.new(@config)
33
34
 
34
35
  class << self
35
36
  extend Forwardable
36
37
 
37
38
  def_delegators :@queues, :pause!, :unpause!, :paused?
39
+ def_delegators :@config, :redis_key
38
40
 
39
41
  def paused_queues
40
42
  @queues.map { |queue| "#{Queues::QUEUE_PREFIX}#{queue}" }
@@ -42,43 +44,45 @@ module Sidekiq
42
44
 
43
45
  def configure
44
46
  MUTEX.synchronize do
45
- yield @config
47
+ config = @config.dup
48
+
49
+ yield config
50
+
51
+ @config = config.freeze
52
+
53
+ self
46
54
  ensure
47
- start_refresher = @queues.refresher_running?
48
- @queues.stop_refresher
49
- @queues = Queues.new(@config)
50
- @queues.start_refresher if start_refresher
55
+ reinit_queues
51
56
  end
52
57
  end
53
58
 
54
59
  def startup
55
60
  MUTEX.synchronize { @queues.start_refresher }
61
+
62
+ self
56
63
  end
57
64
 
58
65
  def shutdown
59
66
  MUTEX.synchronize { @queues.stop_refresher }
60
- end
61
- end
62
- end
63
67
 
64
- class Queue
65
- remove_method :paused?
66
-
67
- def paused?
68
- Pauzer.paused?(name)
69
- end
68
+ self
69
+ end
70
70
 
71
- def pause!
72
- Pauzer.pause!(name)
73
- end
71
+ private
74
72
 
75
- def unpause!
76
- Pauzer.unpause!(name)
73
+ def reinit_queues
74
+ start_refresher = @queues.refresher_running?
75
+ @queues.stop_refresher
76
+ @queues = Queues.new(@config)
77
+ @queues.start_refresher if start_refresher
78
+ end
77
79
  end
78
80
  end
79
81
 
80
82
  configure_server do |config|
81
- config.on(:startup) { Pauzer.startup }
83
+ config.on(:startup) { Pauzer.startup }
82
84
  config.on(:shutdown) { Pauzer.shutdown }
83
85
  end
84
86
  end
87
+
88
+ Sidekiq::Pauzer::Patches::Queue.apply!
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.alpha
4
+ version: 1.0.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-03 00:00:00.000000000 Z
11
+ date: 2023-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -53,7 +53,11 @@ files:
53
53
  - lib/sidekiq/pauzer/adapters/redis_client.rb
54
54
  - lib/sidekiq/pauzer/basic_fetch.rb
55
55
  - lib/sidekiq/pauzer/config.rb
56
+ - lib/sidekiq/pauzer/patches/queue.rb
57
+ - lib/sidekiq/pauzer/patches/web_action.rb
58
+ - lib/sidekiq/pauzer/patches/web_application.rb
56
59
  - lib/sidekiq/pauzer/queues.rb
60
+ - lib/sidekiq/pauzer/runtime.rb
57
61
  - lib/sidekiq/pauzer/version.rb
58
62
  - lib/sidekiq/pauzer/web.rb
59
63
  - web/views/queues.erb
@@ -62,9 +66,9 @@ licenses:
62
66
  - MIT
63
67
  metadata:
64
68
  homepage_uri: https://gitlab.com/ixti/sidekiq-pauzer
65
- source_code_uri: https://gitlab.com/ixti/sidekiq-pauzer/tree/v1.0.0.alpha
69
+ source_code_uri: https://gitlab.com/ixti/sidekiq-pauzer/tree/v1.0.0
66
70
  bug_tracker_uri: https://gitlab.com/ixti/sidekiq-pauzer/issues
67
- changelog_uri: https://gitlab.com/ixti/sidekiq-pauzer/blob/v1.0.0.alpha/CHANGES.md
71
+ changelog_uri: https://gitlab.com/ixti/sidekiq-pauzer/blob/v1.0.0/CHANGES.md
68
72
  rubygems_mfa_required: 'true'
69
73
  post_install_message:
70
74
  rdoc_options: []
@@ -77,9 +81,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
81
  version: '2.7'
78
82
  required_rubygems_version: !ruby/object:Gem::Requirement
79
83
  requirements:
80
- - - ">"
84
+ - - ">="
81
85
  - !ruby/object:Gem::Version
82
- version: 1.3.1
86
+ version: '0'
83
87
  requirements: []
84
88
  rubygems_version: 3.4.10
85
89
  signing_key: