sidekiq-limit_fetch 2.1.3 → 2.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
  SHA1:
3
- metadata.gz: d460d8048f5d1ef64e257f8af49ec1b7274eb966
4
- data.tar.gz: 97b99fee5c035683ab9a8658d263190e0c5b2abd
3
+ metadata.gz: 99b2b29e276cbdb7e9c974939f367eba90ad62f4
4
+ data.tar.gz: 5076f7ceff7dd7e1e90d70fe8dd0e31dd48b8d6a
5
5
  SHA512:
6
- metadata.gz: ebe51888c40335c3a8328536f5c3b57351bc856527c1b0acbb2f9e7818c70d911a3334735e123140b5aea04cce7571b564e8a4b74cc27725139337f1290c7169
7
- data.tar.gz: b3e054be32248f8200615dc8c3b06e4f6d02c2e209eae5676fd8da44693b508f81c3ff3cf6add2a39a179fe18e963f8dda21136be5a6a9e59b846eefec8bcbb1
6
+ metadata.gz: a46d655a1c87cb0712fa22b134914992269aa3130469a2db05f1d8be107893aec01876e508a90178f736ae76d2f0b55e3aea6b27652782bd4635a80450ca5d8f
7
+ data.tar.gz: c47afed022d59b2c60183e02abfa3c11af41b55d35500b91b35c0e913a1bb037170500e8de3da46e7ed0950a99508635e4c8b2e3eaca06bfe2ced16171ee491c
data/README.md CHANGED
@@ -26,6 +26,8 @@ https://devcenter.heroku.com/articles/redistogo#redis-2-6
26
26
 
27
27
  **Important note:** At this moment, `sidekiq-limit_fetch` is incompatible with Sidekiq Pro's `reliable_fetch`.
28
28
 
29
+ https://github.com/mperham/sidekiq/issues/1508 — a sidekiq admin busy page is unreliable, so if you need to check how many workers are running a queue use a `#busy` method described below.
30
+
29
31
  ## Usage
30
32
 
31
33
  ### Limits
data/demo/README.md CHANGED
@@ -1,2 +1,37 @@
1
- To test effect of limits run: `rake demo:limits`
2
- To change simulation see `Rakefile`
1
+ This is a demo rails app with a configured sidekiq-limit_fetch.
2
+
3
+ Its purpose is to check whether plugin works in certain situations.
4
+
5
+ Application is preconfigured with two workers:
6
+ - `app/workers/fast_worker.rb` which does `sleep 0.2`
7
+ - `app/workers/slow_worker.rb` which does `sleep 1`
8
+
9
+ There is also a rake task which can be invoked as `bundle exec rake demo:limit`:
10
+
11
+ - it prefills sidekiq tasks
12
+
13
+ ```ruby
14
+ 100.times do
15
+ SlowWorker.perform_async
16
+ FastWorker.perform_async
17
+ end
18
+ ```
19
+ - sets sidekiq config
20
+
21
+ ```yaml
22
+ :verbose: false
23
+ :concurrency: 4
24
+ :queues:
25
+ - slow
26
+ - fast
27
+ :limits:
28
+ slow: 1
29
+ ```
30
+
31
+ - and launches a sidekiq admin page with overview of queues in browser.
32
+ The page is set to live-poll so effects of limits can be seen directly.
33
+
34
+
35
+ To change simulation modify `Rakefile` or workers.
36
+
37
+ Any bugs related to the plugin should be demonstrated with a reproduction from this base app.
data/demo/Rakefile CHANGED
@@ -22,6 +22,45 @@ namespace :demo do
22
22
  YAML
23
23
  end
24
24
 
25
+ task blocking: :environment do
26
+ puts '=> Creating sidekiq tasks'
27
+
28
+ AWorker.perform_async
29
+ BWorker.perform_async
30
+ CWorker.perform_async
31
+
32
+ run_sidekiq_monitoring
33
+ run_sidekiq_workers config: <<-YAML
34
+ :verbose: false
35
+ :concurrency: 4
36
+ :queues:
37
+ - a
38
+ - b
39
+ - c
40
+ :blocking:
41
+ - a
42
+ YAML
43
+ end
44
+
45
+ task advanced_blocking: :environment do
46
+ puts '=> Creating sidekiq tasks'
47
+
48
+ AWorker.perform_async
49
+ BWorker.perform_async
50
+ CWorker.perform_async
51
+
52
+ run_sidekiq_monitoring
53
+ run_sidekiq_workers config: <<-YAML
54
+ :verbose: false
55
+ :concurrency: 4
56
+ :queues:
57
+ - a
58
+ - b
59
+ - c
60
+ :blocking:
61
+ - [a, b]
62
+ YAML
63
+ end
25
64
  def with_sidekiq_config(config)
26
65
  whitespace_offset = config[/\A */].size
27
66
  config.gsub! /^ {#{whitespace_offset}}/, ''
@@ -51,8 +90,7 @@ namespace :demo do
51
90
  end
52
91
 
53
92
  with_sidekiq_config options[:config] do
54
- config = cli.send :parse_config, 'config/sidekiq.yml'
55
- Sidekiq.options.merge! config
93
+ cli.send :setup_options, []
56
94
  end
57
95
 
58
96
  cli.run
@@ -0,0 +1,8 @@
1
+ class AWorker
2
+ include Sidekiq::Worker
3
+ sidekiq_options queue: :a
4
+
5
+ def perform
6
+ sleep 10
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ class BWorker
2
+ include Sidekiq::Worker
3
+ sidekiq_options queue: :b
4
+
5
+ def perform
6
+ sleep 10
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ class CWorker
2
+ include Sidekiq::Worker
3
+ sidekiq_options queue: :c
4
+
5
+ def perform
6
+ sleep 10
7
+ end
8
+ end
9
+
@@ -82,7 +82,9 @@ module Sidekiq::LimitFetch::Global
82
82
  end
83
83
  end
84
84
 
85
- blocking_mode = can_block and locks > 0
85
+ if not blocking_mode then
86
+ blocking_mode = can_block and locks > 0
87
+ end
86
88
 
87
89
  if blocking_mode and can_block ~= 'true' then
88
90
  for unblocked_queue in string.gmatch(can_block, "[^,]+") do
@@ -18,7 +18,11 @@ module Sidekiq::LimitFetch::Global
18
18
  end
19
19
 
20
20
  def limit=(value)
21
- redis {|it| it.set "#{PREFIX}:limit:#@name", value }
21
+ if value
22
+ redis {|it| it.set "#{PREFIX}:limit:#@name", value }
23
+ else
24
+ redis {|it| it.del "#{PREFIX}:limit:#@name" }
25
+ end
22
26
  end
23
27
 
24
28
  def process_limit
@@ -27,7 +31,11 @@ module Sidekiq::LimitFetch::Global
27
31
  end
28
32
 
29
33
  def process_limit=(value)
30
- redis {|it| it.set "#{PREFIX}:process_limit:#@name", value }
34
+ if value
35
+ redis {|it| it.set "#{PREFIX}:process_limit:#@name", value }
36
+ else
37
+ redis {|it| it.del "#{PREFIX}:process_limit:#@name" }
38
+ end
31
39
  end
32
40
 
33
41
  def acquire
@@ -120,6 +128,15 @@ module Sidekiq::LimitFetch::Global
120
128
 
121
129
  Busy queue processes:
122
130
  #{busy_processes.sort.join "\n"}
131
+
132
+ Limit:
133
+ #{limit.inspect}
134
+
135
+ Process limit:
136
+ #{process_limit.inspect}
137
+
138
+ Blocking:
139
+ #{blocking?}
123
140
  END
124
141
  end
125
142
 
@@ -32,13 +32,16 @@ class Sidekiq::LimitFetch
32
32
  end
33
33
 
34
34
  def set(limit_type, limits)
35
- return unless limits
36
- limits.each do |name, limit|
37
- Sidekiq::Queue[name].send "#{limit_type}=", limit
35
+ limits ||= {}
36
+ each_queue do |queue|
37
+ limit = limits[queue.name.to_s] || limits[queue.name.to_sym]
38
+ queue.send "#{limit_type}=", limit
38
39
  end
39
40
  end
40
41
 
41
42
  def set_blocks(blocks)
43
+ each_queue(&:unblock)
44
+
42
45
  blocks.to_a.each do |it|
43
46
  if it.is_a? Array
44
47
  it.each {|name| Sidekiq::Queue[name].block_except it }
@@ -66,5 +69,9 @@ class Sidekiq::LimitFetch
66
69
  ensure
67
70
  Thread.current[THREAD_KEY] = nil
68
71
  end
72
+
73
+ def each_queue
74
+ @queues.uniq.each {|it| yield Sidekiq::Queue[it] }
75
+ end
69
76
  end
70
77
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'sidekiq-limit_fetch'
3
- gem.version = '2.1.3'
3
+ gem.version = '2.2.0'
4
4
  gem.license = 'MIT'
5
5
  gem.authors = 'brainopia'
6
6
  gem.email = 'brainopia@evilmartians.com'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-limit_fetch
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - brainopia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-02 00:00:00.000000000 Z
11
+ date: 2014-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
@@ -76,6 +76,9 @@ files:
76
76
  - demo/Gemfile
77
77
  - demo/README.md
78
78
  - demo/Rakefile
79
+ - demo/app/workers/a_worker.rb
80
+ - demo/app/workers/b_worker.rb
81
+ - demo/app/workers/c_worker.rb
79
82
  - demo/app/workers/fast_worker.rb
80
83
  - demo/app/workers/slow_worker.rb
81
84
  - demo/config/application.rb