sidekiq-throttled 0.7.0 → 0.7.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
  SHA1:
3
- metadata.gz: cc5eb064ad2211b8e21d3a5936b953d68174545a
4
- data.tar.gz: 90107848a47f41d73d2646d82a8a6c5c013cad20
3
+ metadata.gz: caf7b98eeb976c1114776cb1981a3bd6b7c218f8
4
+ data.tar.gz: 1945f409e2048660611a1a7ede586bb573899d51
5
5
  SHA512:
6
- metadata.gz: f4471f6d39fa2e29071f6b66fa256e257040c61192b8110e6ef1bc15fd15e93e5b7318250b0f5c76259974c407278490069b9e6ed541f83ab0ce83218ffaf957
7
- data.tar.gz: 4f53ef0e1b5c7cf1a2ba0a1c973525aa4a4ef0cb40809b08435d5d7403cee52664cf685ee0c8b61711573763913e89cc74c09136d65d2b173a560caf4c580dbe
6
+ metadata.gz: 6b6640758e9fea0d59f715d87071da32300dc54e3397b2e9c90f16bbcfb90e9bfd22153e607cdfbbe7cd04359ef0e920f9a59b37c8870bfd467c71b239951e1e
7
+ data.tar.gz: e6ea732bdbb2818828203823a7620fd681eacae992eff09422bc57f9a659ecb1fa992a08e1191c50df0cad346af980000074855c7f87fd705c4af62f8cdd01a1
data/CHANGES.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## 0.7.1 (2017-03-30)
2
+
3
+ * Fix summary bar queues link when queue ui was enhanced.
4
+ ([@ixti])
5
+
6
+ * [#31](https://github.com/sensortower/sidekiq-throttled/pull/31)
7
+ [#30](https://github.com/sensortower/sidekiq-throttled/issues/30)
8
+ Do not throttle if limit is `nil`.
9
+ ([@ixti])
10
+
11
+
1
12
  ## 0.7.0 (2017-03-22)
2
13
 
3
14
  * Expose pause/resume queues hidden feature to UI. This was available via API
@@ -3,7 +3,7 @@
3
3
  require "sidekiq"
4
4
 
5
5
  # internal
6
- require "sidekiq/version"
6
+ require "sidekiq/throttled/version"
7
7
  require "sidekiq/throttled/communicator"
8
8
  require "sidekiq/throttled/queues_pauser"
9
9
  require "sidekiq/throttled/registry"
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sidekiq
4
+ module Throttled
5
+ class Strategy
6
+ module Base
7
+ def limit(job_args = nil)
8
+ @limit.respond_to?(:call) ? @limit.call(*job_args) : @limit
9
+ end
10
+
11
+ private
12
+
13
+ def key(job_args)
14
+ key = @base_key.dup
15
+ key << ":#{@key_suffix.call(*job_args)}" if @key_suffix
16
+ key
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
- # internal
2
+
3
+ require "sidekiq/throttled/strategy/base"
3
4
  require "sidekiq/throttled/strategy/script"
4
5
 
5
6
  module Sidekiq
@@ -7,13 +8,17 @@ module Sidekiq
7
8
  class Strategy
8
9
  # Concurrency throttling strategy
9
10
  class Concurrency
11
+ include Base
12
+
10
13
  # LUA script used to limit fetch concurrency.
11
14
  # Logic behind the scene can be described in following pseudo code:
12
15
  #
13
- # return 1 if @limit <= LLEN(@key)
14
- #
15
- # PUSH(@key, @jid)
16
- # return 0
16
+ # if @limit <= LLEN(@key)
17
+ # return 1
18
+ # else
19
+ # PUSH(@key, @jid)
20
+ # return 0
21
+ # end
17
22
  SCRIPT = Script.read "#{__dir__}/concurrency.lua"
18
23
  private_constant :SCRIPT
19
24
 
@@ -29,12 +34,6 @@ module Sidekiq
29
34
  @key_suffix = key_suffix
30
35
  end
31
36
 
32
- # @return [Integer] Amount of allowed concurrent job processors
33
- def limit(job_args = nil)
34
- return @limit.to_i unless @limit.respond_to? :call
35
- @limit.call(*job_args).to_i
36
- end
37
-
38
37
  # @return [Boolean] Whenever strategy has dynamic config
39
38
  def dynamic?
40
39
  @key_suffix || @limit.respond_to?(:call)
@@ -42,7 +41,12 @@ module Sidekiq
42
41
 
43
42
  # @return [Boolean] whenever job is throttled or not
44
43
  def throttled?(jid, *job_args)
45
- 1 == SCRIPT.eval([key(job_args)], [jid.to_s, limit(job_args), @ttl])
44
+ return false unless (job_limit = limit(job_args))
45
+
46
+ keys = [key(job_args)]
47
+ args = [jid.to_s, job_limit, @ttl]
48
+
49
+ 1 == SCRIPT.eval(keys, args)
46
50
  end
47
51
 
48
52
  # @return [Integer] Current count of jobs
@@ -61,14 +65,6 @@ module Sidekiq
61
65
  def finalize!(jid, *job_args)
62
66
  Sidekiq.redis { |conn| conn.srem(key(job_args), jid.to_s) }
63
67
  end
64
-
65
- private
66
-
67
- def key(job_args)
68
- key = @base_key.dup
69
- key << ":#{@key_suffix.call(*job_args)}" if @key_suffix
70
- key
71
- end
72
68
  end
73
69
  end
74
70
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
- # internal
2
+
3
+ require "sidekiq/throttled/strategy/base"
3
4
  require "sidekiq/throttled/strategy/script"
4
5
 
5
6
  module Sidekiq
@@ -9,6 +10,8 @@ module Sidekiq
9
10
  # @todo Use redis TIME command instead of sending current timestamp from
10
11
  # sidekiq manager. See: http://redis.io/commands/time
11
12
  class Threshold
13
+ include Base
14
+
12
15
  # LUA script used to limit fetch threshold.
13
16
  # Logic behind the scene can be described in following pseudo code:
14
17
  #
@@ -41,12 +44,6 @@ module Sidekiq
41
44
  @key_suffix = key_suffix
42
45
  end
43
46
 
44
- # @return [Integer] Amount of jobs allowed per period
45
- def limit(job_args = nil)
46
- return @limit.to_i unless @limit.respond_to? :call
47
- @limit.call(*job_args).to_i
48
- end
49
-
50
47
  # @return [Float] Period in seconds
51
48
  def period(job_args = nil)
52
49
  return @period.to_f unless @period.respond_to? :call
@@ -60,10 +57,12 @@ module Sidekiq
60
57
 
61
58
  # @return [Boolean] whenever job is throttled or not
62
59
  def throttled?(*job_args)
63
- key = key(job_args)
64
- limit = limit(job_args)
65
- period = period(job_args)
66
- 1 == SCRIPT.eval([key], [limit, period, Time.now.to_f])
60
+ return false unless (job_limit = limit(job_args))
61
+
62
+ keys = [key(job_args)]
63
+ args = [job_limit, period(job_args), Time.now.to_f]
64
+
65
+ 1 == SCRIPT.eval(keys, args)
67
66
  end
68
67
 
69
68
  # @return [Integer] Current count of jobs
@@ -76,14 +75,6 @@ module Sidekiq
76
75
  def reset!(*job_args)
77
76
  Sidekiq.redis { |conn| conn.del(key(job_args)) }
78
77
  end
79
-
80
- private
81
-
82
- def key(job_args)
83
- key = @base_key.dup
84
- key << ":#{@key_suffix.call(*job_args)}" if @key_suffix
85
- key
86
- end
87
78
  end
88
79
  end
89
80
  end
@@ -3,6 +3,6 @@
3
3
  module Sidekiq
4
4
  module Throttled
5
5
  # Gem version
6
- VERSION = "0.7.0"
6
+ VERSION = "0.7.1"
7
7
  end
8
8
  end
@@ -10,6 +10,7 @@ require "sidekiq/web"
10
10
  # internal
11
11
  require "sidekiq/throttled/registry"
12
12
  require "sidekiq/throttled/web/stats"
13
+ require "sidekiq/throttled/web/summary_fix"
13
14
 
14
15
  module Sidekiq
15
16
  module Throttled
@@ -22,6 +23,7 @@ module Sidekiq
22
23
  class << self
23
24
  # Replace default Queues tab with enhanced one.
24
25
  def enhance_queues_tab!
26
+ SummaryFix.enabled = true
25
27
  Sidekiq::Web::DEFAULT_TABS["Queues"] = "enhanced-queues"
26
28
  Sidekiq::Web.tabs.delete("Enhanced Queues")
27
29
  end
@@ -31,12 +33,14 @@ module Sidekiq
31
33
  # @api There's next to absolutely no value in this method for real
32
34
  # users. The only it's purpose is to restore virgin state in specs.
33
35
  def restore_queues_tab!
36
+ SummaryFix.enabled = false
34
37
  Sidekiq::Web::DEFAULT_TABS["Queues"] = "queues"
35
38
  Sidekiq::Web.tabs["Enhanced Queues"] = "enhanced-queues"
36
39
  end
37
40
 
38
41
  # @api private
39
42
  def registered(app)
43
+ app.send(:include, SummaryFix)
40
44
  register_throttled_tab app
41
45
  register_enhanced_queues_tab app
42
46
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sidekiq
4
+ module Throttled
5
+ module Web
6
+ module SummaryFix
7
+ JAVASCRIPT = <<-JAVASCRIPT
8
+ <script>
9
+ $(function ($el) {
10
+ var $el = $(".summary li.enqueued > a"),
11
+ url = $el.attr("href").replace(/\/queues$/, "/enhanced-queues");
12
+ $el.attr("href", url);
13
+ });
14
+ </script>
15
+ JAVASCRIPT
16
+
17
+ class << self
18
+ attr_accessor :enabled
19
+ end
20
+
21
+ def display_custom_head
22
+ SummaryFix.enabled ? "#{super}#{JAVASCRIPT}" : super
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-throttled
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey V Zapparov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-22 00:00:00.000000000 Z
11
+ date: 2017-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
@@ -76,6 +76,7 @@ files:
76
76
  - lib/sidekiq/throttled/queues_pauser.rb
77
77
  - lib/sidekiq/throttled/registry.rb
78
78
  - lib/sidekiq/throttled/strategy.rb
79
+ - lib/sidekiq/throttled/strategy/base.rb
79
80
  - lib/sidekiq/throttled/strategy/concurrency.lua
80
81
  - lib/sidekiq/throttled/strategy/concurrency.rb
81
82
  - lib/sidekiq/throttled/strategy/script.rb
@@ -86,6 +87,7 @@ files:
86
87
  - lib/sidekiq/throttled/web.rb
87
88
  - lib/sidekiq/throttled/web/queues.html.erb
88
89
  - lib/sidekiq/throttled/web/stats.rb
90
+ - lib/sidekiq/throttled/web/summary_fix.rb
89
91
  - lib/sidekiq/throttled/web/throttled.html.erb
90
92
  - lib/sidekiq/throttled/worker.rb
91
93
  - sidekiq-throttled.gemspec
@@ -109,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
111
  version: '0'
110
112
  requirements: []
111
113
  rubyforge_project:
112
- rubygems_version: 2.6.8
114
+ rubygems_version: 2.6.11
113
115
  signing_key:
114
116
  specification_version: 4
115
117
  summary: Concurrency and threshold throttling for Sidekiq.