sidekiq_autoscale 0.2.3 → 0.2.6

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: 1cfb3c09aae5e59a3b70e5f59dfcec134f6fdd76967d85dde6a938fd923e7798
4
- data.tar.gz: 1ab3220369cc25eb91b3b38181c5a1c54cae20898afae858a3d56b275346344e
3
+ metadata.gz: 35870ccd72ae7e188ecde7da83579cc245dcfaef933796e446c29796bb834a08
4
+ data.tar.gz: f1c34d154270893707aa7fc0b2888f8c89008733f9db5e6305a5611befd8dff7
5
5
  SHA512:
6
- metadata.gz: 0e2f36159a9cc83d9f8f9b46b7b902758e966281b2e28d73fcfa8dd8b5559ad97ff58b0bd7eeb36de5cf52868b24c430786ab8c65c6bb71675e4c7ae52e61913
7
- data.tar.gz: 8d1ae14cdcb5e82d7a355337f5836ee1c21cb0672d475f3aa54ac0efa81512789886ba35423071cc4bb7c7b5c25a7af493d2fe9b6ac81517a1e6ba448692e833
6
+ metadata.gz: 3677436e3a7872319dca5d7549c0bf611b428fb8192f4e377e4983751ca2f9ff10196c9d5811efa66e9cba5589b92750d925776ad38f33f17c99cfb88d0f99ef
7
+ data.tar.gz: 9e059d8e41ee804561d24ac986ce535d228c36541514cd8ee6d57094cbb70dc308f593edcb2346084a04e5b92a036bf5a8f22a0e4f4199f09dbcbe547c245051
data/README.md CHANGED
@@ -148,5 +148,33 @@ metadata:
148
148
 
149
149
  Then assign your sidekiq deployment the `myapp-sidekiq` service account.
150
150
 
151
+ ## Multiple sidekiq pools
152
+
153
+ Sidekiq autoscaler works with multiple Sidekiq pools that run off a single redis instance.
154
+
155
+ A typical use case for this would be a client pushing jobs to the same Redis backend,
156
+ which are then processed by multiple sets of workers (i.e. high CPU vs. high memory instances).
157
+
158
+ If so, you need to set two environment variables in each pool:
159
+ * `SIDEKIQ_QUEUES` - list of queues to be processed
160
+ * `SIDEKIQ_POOL` - name of the pool
161
+
162
+ You also need to use `$SIDEKIQ_POOL` tag when starting sidekiq processs.
163
+
164
+ Example:
165
+
166
+ ```
167
+ # High priority pool
168
+ SIDEKIQ_QUEUES='["critical", "urgent"]'
169
+ SIDEKIQ_POOL=high
170
+
171
+ # Low priority pool
172
+ SIDEKIQ_QUEUES='["default", "low", "searchkick"]'
173
+ SIDEKIQ_POOL=low
174
+
175
+ # Start sidekiq
176
+ bundle exec sidekiq -C config/sidekiq.yml -g $SIDEKIQ_POOL
177
+ ```
178
+
151
179
  ## License
152
180
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -15,9 +15,12 @@ module SidekiqAutoscale
15
15
 
16
16
  def worker_count
17
17
  @resources.get(@deployment_name).spec.replicas
18
- rescue Excon::Errors::Error, K8s::Error, K8s::Error::Forbidden => e
18
+ rescue K8s::Error, K8s::Error::Forbidden => e
19
19
  SidekiqAutoscale.on_scaling_error(e)
20
20
  0
21
+ rescue Excon::Errors::Error, Excon::Error::Socket => e
22
+ SidekiqAutoscale.logger.warn("[SIDEKIQ_SCALE][KUBERNETES_ACTION] Error connecting to Kubernetes: #{e}")
23
+ 0
21
24
  end
22
25
 
23
26
  def worker_count=(val)
@@ -2,10 +2,11 @@
2
2
 
3
3
  module SidekiqAutoscale
4
4
  class Middleware
5
- LAST_SCALED_AT_EVENT_KEY = "sidekiq_autoscaling:last_scaled_at"
6
- SCALING_LOCK_KEY = "sidekiq_autoscaling:scaling_lock"
5
+ POOL_NAME = ENV.fetch("SIDEKIQ_POOL", "default")
6
+ LAST_SCALED_AT_EVENT_KEY = "sidekiq_autoscaling:#{POOL_NAME}:last_scaled_at"
7
+ SCALING_LOCK_KEY = "sidekiq_autoscaling:#{POOL_NAME}:scaling_lock"
7
8
  LOG_TAG = "[SIDEKIQ_SCALE][SCALING_EVENT]"
8
- WORKER_COUNT_KEY = "sidekiq_autoscaling/current_worker_count"
9
+ WORKER_COUNT_KEY = "sidekiq_autoscaling/#{POOL_NAME}/current_worker_count"
9
10
 
10
11
  # @param [Object] worker the worker instance
11
12
  # @param [Hash] job the full job payload
@@ -9,7 +9,12 @@ module SidekiqAutoscale
9
9
  end
10
10
 
11
11
  def queue_names
12
- ::Sidekiq::Queue.all.map(&:name)
12
+ from_env = ENV["SIDEKIQ_QUEUES"]
13
+ if from_env
14
+ JSON.parse(from_env)
15
+ else
16
+ ::Sidekiq::Queue.all.map(&:name)
17
+ end
13
18
  end
14
19
 
15
20
  def busy_threads
@@ -39,7 +44,13 @@ module SidekiqAutoscale
39
44
  private
40
45
 
41
46
  def process_set
42
- @process_set ||= ::Sidekiq::ProcessSet.new
47
+ @process_set ||= begin
48
+ ps = ::Sidekiq::ProcessSet.new
49
+ pool = ENV["SIDEKIQ_POOL"]
50
+
51
+ ps = ps.select {|process| process.tag == pool } if pool
52
+ ps
53
+ end
43
54
  end
44
55
  end
45
56
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SidekiqAutoscale
4
- VERSION = "0.2.3"
4
+ VERSION = "0.2.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq_autoscale
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Allen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-09 00:00:00.000000000 Z
11
+ date: 2022-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -56,14 +56,14 @@ dependencies:
56
56
  name: railties
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: 5.2.6
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: 5.2.6
69
69
  - !ruby/object:Gem::Dependency
@@ -358,7 +358,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
358
358
  - !ruby/object:Gem::Version
359
359
  version: '0'
360
360
  requirements: []
361
- rubygems_version: 3.2.32
361
+ rubygems_version: 3.3.7
362
362
  signing_key:
363
363
  specification_version: 4
364
364
  summary: A simple gem to handle Sidekiq autoscaling.