sidekiq-limit_fetch 3.3.1 → 3.4.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: c949366fce8ef0a1f51ccef3973bded9c94c639a
4
- data.tar.gz: c85ead7127f04b16efa8e50459bb0943b876762c
3
+ metadata.gz: 90670344f1d8eaa97d215118db466740393123aa
4
+ data.tar.gz: 3364780aa3ff90b22d4156d7a2eb6b315ca072b9
5
5
  SHA512:
6
- metadata.gz: 8204753f854ed3af8a6e05884fb739079059c0c9723c25daf8b7206b832ebfc92afd3197f42a19ba92da5bf1c3327e01955277ff12a993b0d1f5346bd100a410
7
- data.tar.gz: 26e0d3c81fc68942382d8d55f15e3fa018603afd788610d4bf1c294bf957f3c7dd70975bdbf5663b3aa90ab4da2381938eebd90bb77b12aec72c8682a323de3f
6
+ metadata.gz: f27825c415fa9995330e61bf78877fe20bbb1e1af4782d9e3072803092a55e170569d80cdd9f8bd0966c81c562fda120f5b0fd878b06e78532731e5490a20bfd
7
+ data.tar.gz: 1d326108a6cc523131e44337c3f7e43116f7775d6f7a538b5d4a6ce63f276010a9ee379429bec18be725931ecd35d20a5f2b2eeb5bb3df5eeb86e5df406bbe95
@@ -4,14 +4,18 @@ module Sidekiq::LimitFetch::Queues
4
4
  THREAD_KEY = :acquired_queues
5
5
 
6
6
  def start(options)
7
- @queues = options[:queues]
8
- @dynamic = options[:dynamic]
7
+ @queues = options[:queues]
8
+ @dynamic = options[:dynamic]
9
+
10
+ @limits = options[:limits] || {}
11
+ @process_limits = options[:process_limits] || {}
12
+ @blocks = options[:blocking] || []
9
13
 
10
14
  options[:strict] ? strict_order! : weighted_order!
11
15
 
12
- set :process_limit, options[:process_limits]
13
- set :limit, options[:limits]
14
- set_blocks options[:blocking]
16
+ apply_process_limit_to_queues
17
+ apply_limit_to_queues
18
+ apply_blocks_to_queues
15
19
  end
16
20
 
17
21
  def acquire
@@ -35,7 +39,12 @@ module Sidekiq::LimitFetch::Queues
35
39
 
36
40
  def add(queues)
37
41
  queues.each do |queue|
38
- @queues.push queue unless @queues.include? queue
42
+ unless @queues.include? queue
43
+ apply_process_limit_to_queue(queue)
44
+ apply_limit_to_queue(queue)
45
+
46
+ @queues.push queue
47
+ end
39
48
  end
40
49
  end
41
50
 
@@ -60,22 +69,37 @@ module Sidekiq::LimitFetch::Queues
60
69
 
61
70
  private
62
71
 
63
- def selector
64
- Sidekiq::LimitFetch::Global::Selector
72
+ def apply_process_limit_to_queues
73
+ @queues.uniq.each do |queue_name|
74
+ apply_process_limit_to_queue(queue_name)
75
+ end
76
+ end
77
+
78
+ def apply_process_limit_to_queue(queue_name)
79
+ queue = Sidekiq::Queue[queue_name]
80
+ queue.process_limit = @process_limits[queue_name.to_s] || @process_limits[queue_name.to_sym]
65
81
  end
66
82
 
67
- def set(limit_type, limits)
68
- limits ||= {}
69
- each_queue do |queue|
70
- limit = limits[queue.name.to_s] || limits[queue.name.to_sym]
71
- queue.send "#{limit_type}=", limit unless queue.limit_changed?
83
+ def apply_limit_to_queues
84
+ @queues.uniq.each do |queue_name|
85
+ apply_limit_to_queue(queue_name)
72
86
  end
73
87
  end
74
88
 
75
- def set_blocks(blocks)
76
- each_queue(&:unblock)
89
+ def apply_limit_to_queue(queue_name)
90
+ queue = Sidekiq::Queue[queue_name]
77
91
 
78
- blocks.to_a.each do |it|
92
+ unless queue.limit_changed?
93
+ queue.limit = @limits[queue_name.to_s] || @limits[queue_name.to_sym]
94
+ end
95
+ end
96
+
97
+ def apply_blocks_to_queues
98
+ @queues.uniq.each do |queue_name|
99
+ Sidekiq::Queue[queue_name].unblock
100
+ end
101
+
102
+ @blocks.to_a.each do |it|
79
103
  if it.is_a? Array
80
104
  it.each {|name| Sidekiq::Queue[name].block_except it }
81
105
  else
@@ -84,6 +108,10 @@ module Sidekiq::LimitFetch::Queues
84
108
  end
85
109
  end
86
110
 
111
+ def selector
112
+ Sidekiq::LimitFetch::Global::Selector
113
+ end
114
+
87
115
  def save(queues)
88
116
  Thread.current[THREAD_KEY] = queues
89
117
  end
@@ -93,8 +121,4 @@ module Sidekiq::LimitFetch::Queues
93
121
  ensure
94
122
  Thread.current[THREAD_KEY] = nil
95
123
  end
96
-
97
- def each_queue
98
- @queues.uniq.each {|it| yield Sidekiq::Queue[it] }
99
- end
100
124
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'sidekiq-limit_fetch'
3
- gem.version = '3.3.1'
3
+ gem.version = '3.4.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: 3.3.1
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - brainopia
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-12 00:00:00.000000000 Z
11
+ date: 2016-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
@@ -17,13 +17,13 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4'
20
- type: :runtime
21
- prerelease: false
22
20
  version_requirements: !ruby/object:Gem::Requirement
23
21
  requirements:
24
22
  - - ">="
25
23
  - !ruby/object:Gem::Version
26
24
  version: '4'
25
+ prerelease: false
26
+ type: :runtime
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: redis-namespace
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -34,8 +34,6 @@ dependencies:
34
34
  - - ">="
35
35
  - !ruby/object:Gem::Version
36
36
  version: 1.5.2
37
- type: :development
38
- prerelease: false
39
37
  version_requirements: !ruby/object:Gem::Requirement
40
38
  requirements:
41
39
  - - "~>"
@@ -44,6 +42,8 @@ dependencies:
44
42
  - - ">="
45
43
  - !ruby/object:Gem::Version
46
44
  version: 1.5.2
45
+ prerelease: false
46
+ type: :development
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -51,13 +51,13 @@ dependencies:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
- type: :development
55
- prerelease: false
56
54
  version_requirements: !ruby/object:Gem::Requirement
57
55
  requirements:
58
56
  - - ">="
59
57
  - !ruby/object:Gem::Version
60
58
  version: '0'
59
+ prerelease: false
60
+ type: :development
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rake
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -65,13 +65,13 @@ dependencies:
65
65
  - - ">="
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
- type: :development
69
- prerelease: false
70
68
  version_requirements: !ruby/object:Gem::Requirement
71
69
  requirements:
72
70
  - - ">="
73
71
  - !ruby/object:Gem::Version
74
72
  version: '0'
73
+ prerelease: false
74
+ type: :development
75
75
  description: |2
76
76
  Sidekiq strategy to restrict number of workers
77
77
  which are able to run specified queues simultaneously.
@@ -121,7 +121,7 @@ homepage: https://github.com/brainopia/sidekiq-limit_fetch
121
121
  licenses:
122
122
  - MIT
123
123
  metadata: {}
124
- post_install_message:
124
+ post_install_message:
125
125
  rdoc_options: []
126
126
  require_paths:
127
127
  - lib
@@ -136,9 +136,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  - !ruby/object:Gem::Version
137
137
  version: '0'
138
138
  requirements: []
139
- rubyforge_project:
140
- rubygems_version: 2.5.1
141
- signing_key:
139
+ rubyforge_project:
140
+ rubygems_version: 2.6.4
141
+ signing_key:
142
142
  specification_version: 4
143
143
  summary: Sidekiq strategy to support queue limits
144
144
  test_files: