sidekiq-throttled 0.17.0 → 1.0.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/{README.md → README.adoc} +95 -114
  3. data/lib/sidekiq/throttled/basic_fetch.rb +55 -0
  4. data/lib/sidekiq/throttled/fetch.rb +3 -87
  5. data/lib/sidekiq/throttled/job.rb +1 -1
  6. data/lib/sidekiq/throttled/middleware.rb +3 -1
  7. data/lib/sidekiq/throttled/registry.rb +2 -5
  8. data/lib/sidekiq/throttled/strategy/concurrency.rb +4 -6
  9. data/lib/sidekiq/throttled/strategy/threshold.rb +4 -6
  10. data/lib/sidekiq/throttled/strategy.rb +10 -10
  11. data/lib/sidekiq/throttled/strategy_collection.rb +1 -1
  12. data/lib/sidekiq/throttled/version.rb +1 -1
  13. data/lib/sidekiq/throttled/web.rb +2 -45
  14. data/lib/sidekiq/throttled/worker.rb +1 -1
  15. data/lib/sidekiq/throttled.rb +16 -50
  16. metadata +20 -80
  17. data/.coveralls.yml +0 -1
  18. data/.github/dependabot.yml +0 -12
  19. data/.github/workflows/ci.yml +0 -52
  20. data/.gitignore +0 -12
  21. data/.rspec +0 -5
  22. data/.rubocop.yml +0 -20
  23. data/.rubocop_todo.yml +0 -68
  24. data/.travis.yml +0 -37
  25. data/.yardopts +0 -1
  26. data/Appraisals +0 -9
  27. data/CHANGES.md +0 -300
  28. data/Gemfile +0 -34
  29. data/Guardfile +0 -25
  30. data/Rakefile +0 -27
  31. data/gemfiles/sidekiq_6.4.gemfile +0 -33
  32. data/gemfiles/sidekiq_6.5.gemfile +0 -33
  33. data/lib/sidekiq/throttled/communicator/callbacks.rb +0 -72
  34. data/lib/sidekiq/throttled/communicator/exception_handler.rb +0 -25
  35. data/lib/sidekiq/throttled/communicator/listener.rb +0 -109
  36. data/lib/sidekiq/throttled/communicator.rb +0 -116
  37. data/lib/sidekiq/throttled/expirable_list.rb +0 -70
  38. data/lib/sidekiq/throttled/fetch/unit_of_work.rb +0 -83
  39. data/lib/sidekiq/throttled/patches/queue.rb +0 -18
  40. data/lib/sidekiq/throttled/queue_name.rb +0 -46
  41. data/lib/sidekiq/throttled/queues_pauser.rb +0 -152
  42. data/lib/sidekiq/throttled/testing.rb +0 -12
  43. data/lib/sidekiq/throttled/utils.rb +0 -19
  44. data/lib/sidekiq/throttled/web/queues.html.erb +0 -49
  45. data/lib/sidekiq/throttled/web/summary_fix.js +0 -10
  46. data/lib/sidekiq/throttled/web/summary_fix.rb +0 -35
  47. data/rubocop/layout.yml +0 -24
  48. data/rubocop/lint.yml +0 -41
  49. data/rubocop/metrics.yml +0 -4
  50. data/rubocop/performance.yml +0 -25
  51. data/rubocop/rspec.yml +0 -3
  52. data/rubocop/style.yml +0 -84
  53. data/sidekiq-throttled.gemspec +0 -36
  54. /data/{LICENSE.md → LICENSE} +0 -0
data/CHANGES.md DELETED
@@ -1,300 +0,0 @@
1
- ## 0.16.1 (2022-06-14)
2
-
3
- * [#2](https://github.com/ixti/sidekiq-throttled/pull/2)
4
- Support custom ActiveJob adapters.
5
- ([@longkt90])
6
-
7
- * [#107](https://github.com/sensortower/sidekiq-throttled/pull/107)
8
- Log error when key sufix extraction fails.
9
- ([@pjungwir])
10
-
11
- ## 0.16.0 (2022-06-13)
12
-
13
- * Drop Ruby 2.6 support.
14
-
15
- * Drop Sidekiq 5.X support.
16
-
17
- * [#121](https://github.com/sensortower/sidekiq-throttled/pull/121)
18
- Sidekiq 6.5 compatibility.
19
- ([@hieuk09])
20
-
21
- * [#116](https://github.com/sensortower/sidekiq-throttled/pull/116)
22
- Unwrap ActiveJob JobWrapper
23
- ([@holstvoogd])
24
-
25
- * [#115](https://github.com/sensortower/sidekiq-throttled/pull/115)
26
- Fix Redis 4.6 deprecation warnings.
27
- ([@dbackeus])
28
-
29
- * [#113](https://github.com/sensortower/sidekiq-throttled/pull/113)
30
- Add Ruby 3.1 to CI.
31
- ([@petergoldstein])
32
-
33
- * [#103](https://github.com/sensortower/sidekiq-throttled/pull/103)
34
- Rename Sidekiq::Throttled::Worker to Sidekiq::Throttled::Job, and alias it
35
- as Sidekiq::Throttled::Worker.
36
- ([@CHTJonas])
37
-
38
- ## 0.15.0 (2021-12-16)
39
-
40
- * [#102](https://github.com/sensortower/sidekiq-throttled/pull/102)
41
- Support Ruby 3.0 and Sidekiq 6.2+.
42
- ([@ybiquitous])
43
-
44
- * [#97](https://github.com/sensortower/sidekiq-throttled/pull/97)
45
- Fix kwargs usage in strategy collection.
46
- ([@baptistejub])
47
-
48
- ## 0.14.0 (2021-09-21)
49
-
50
- * [#98](https://github.com/sensortower/sidekiq-throttled/pull/98)
51
- Remove warning for strategy override.
52
- ([@mattiagiuffrida-st])
53
-
54
- * [#65](https://github.com/sensortower/sidekiq-throttled/pull/65)
55
- Support composite (multi-key) strategies.
56
- ([@holyketzer])
57
-
58
- * [#89](https://github.com/sensortower/sidekiq-throttled/pull/89),
59
- [#96](https://github.com/sensortower/sidekiq-throttled/pull/96), and
60
- [#93](https://github.com/sensortower/sidekiq-throttled/pull/93)
61
- Improve documentation.
62
- ([@hubertjakubiak], [@khaile], and [@kylerippey])
63
-
64
- ## 0.13.0 (2020-07-28)
65
-
66
- * [#85](https://github.com/sensortower/sidekiq-throttled/pull/85)
67
- Add Sidekiq 6.1+ support.
68
- ([@hmaack])
69
-
70
- ## 0.12.0 (2020-06-22)
71
-
72
- * [#80](https://github.com/sensortower/sidekiq-throttled/pull/80)
73
- Allow override cooldown timeout of queues with throttled jobs.
74
- ([@vaot])
75
-
76
- * [#76](https://github.com/sensortower/sidekiq-throttled/pull/76)
77
- Fix warnings on Ruby 2.7
78
- ([@lenon])
79
-
80
-
81
- ## 0.11.0 (2019-08-24)
82
-
83
- * [#59](https://github.com/sensortower/sidekiq-throttled/pull/59)
84
- Add throttling observer.
85
- ([@ogins57])
86
-
87
-
88
- ## 0.10.0 (2019-06-22)
89
-
90
- * [#60](https://github.com/sensortower/sidekiq-throttled/pull/60)
91
- Skip throttling check in redis if limit is 0.
92
- ([@mstruve])
93
-
94
- * [#58](https://github.com/sensortower/sidekiq-throttled/pull/58)
95
- Improve documentation bout TTL.
96
- ([@ziaulrehman40])
97
-
98
- * Improve reliability of paused queues, by resyncing list of paused queues
99
- on schedule.
100
- ([@ixti])
101
-
102
-
103
- ## 0.9.0 (2018-09-11)
104
-
105
- * Add support of Sidekiq 5.2.x
106
- ([@ixti])
107
-
108
- * Drop support of Sidekiq 4.x
109
- ([@ixti])
110
-
111
- * Add concurrent-ruby as dependency which is no longer a dependency of
112
- Sidekiq as 5.2+ version.
113
- ([@ixti])
114
-
115
-
116
- ## 0.8.2 (2018-02-14)
117
-
118
- * Extract redis LUA scripts stored procedures runner to redis-prescription gem.
119
- ([@ixti])
120
-
121
- * Switch to Concurrent.monotonic_time to expire elements of ExpirableList.
122
- ([@ixti])
123
-
124
-
125
- ## 0.8.1 (2017-11-02)
126
-
127
- * Preload job class constant prior trying to get it's throttling strategy.
128
- ([@ixti])
129
-
130
-
131
- ## 0.8.0 (2017-10-11)
132
-
133
- * Refactor concurrency throttling internals to use sorted sets in order to avoid
134
- starvation in case when finalize! was not called (OOM / redis issues).
135
- ([@ixti])
136
-
137
-
138
- ## 0.7.3 (2017-06-26)
139
-
140
- * [#34](https://github.com/sensortower/sidekiq-throttled/issues/34)
141
- Fix reset button for sidekiq `>= 4.2`.
142
- ([@ixti])
143
-
144
-
145
- ## 0.7.2 (2017-04-02)
146
-
147
- * Fix summary bar fixer on sidekiq 4.2+.
148
- ([@ixti])
149
-
150
- * Fix regexp used to fix summay bar queues link when ui was enhanced.
151
- ([@ixti])
152
-
153
-
154
- ## 0.7.1 (2017-03-30)
155
-
156
- * Fix summary bar queues link when queue ui was enhanced.
157
- ([@ixti])
158
-
159
- * [#31](https://github.com/sensortower/sidekiq-throttled/pull/31)
160
- [#30](https://github.com/sensortower/sidekiq-throttled/issues/30)
161
- Do not throttle if limit is `nil`.
162
- ([@ixti])
163
-
164
-
165
- ## 0.7.0 (2017-03-22)
166
-
167
- * Expose pause/resume queues hidden feature to UI. This was available via API
168
- since v0.6.0 and today it's finally got it's UI.
169
- ([@ixti])
170
-
171
-
172
- ## 0.6.7 (2017-03-21)
173
-
174
- * Fix fetcher causing workers starvation upon low concurrency thresholds.
175
- ([@ixti])
176
-
177
-
178
- ## 0.6.6 (2016-10-16)
179
-
180
- * [#24](https://github.com/sensortower/sidekiq-throttled/pull/24)
181
- Fix dynamic `:key_suffix` issue.
182
- ([@iporsut])
183
-
184
-
185
- ## 0.6.5 (2016-09-04)
186
-
187
- * Fix concurrency throttling when redis-namespace is used.
188
- ([@ixti])
189
-
190
-
191
- ## 0.6.4 (2016-09-02)
192
-
193
- * Rename UnitOfWork throttled requeue to `#requeue_throttled`.
194
- ([@ixti])
195
-
196
-
197
- ## 0.6.3 (2016-09-02)
198
-
199
- * Enrich internal API to allow better extensibility.
200
- ([@ixti])
201
-
202
-
203
- ## 0.6.2 (2016-09-01)
204
-
205
- * Add `Fetch.bulk_requeue` used by Sidekiq upon termination.
206
- ([@ixti])
207
-
208
-
209
- ## 0.6.1 (2016-08-30)
210
-
211
- * Trivial internal API change: extracted queues list builder of `Fetch` into
212
- dedicated internal method, allowing to enhance it with extra custom filters.
213
- ([@ixti])
214
-
215
-
216
- ## 0.6.0 (2016-08-27)
217
-
218
- * [#21](https://github.com/sensortower/sidekiq-throttled/pull/21)
219
- Allow pause/unpause queues.
220
- ([@ixti])
221
-
222
-
223
- ## 0.5.0 (2016-08-18)
224
-
225
- * Drop Sidekiq 3.x support.
226
- ([@ixti])
227
-
228
-
229
- ## 0.4.1 (2016-08-18)
230
-
231
- * [#15](https://github.com/sensortower/sidekiq-throttled/pull/15)
232
- Fix throttled web UI on older versions of sidekiq.
233
- ([@palanglung])
234
-
235
-
236
- ## 0.4.0 (2016-05-17)
237
-
238
- * [#14](https://github.com/sensortower/sidekiq-throttled/pull/14)
239
- Support dynamic configuration of limits and periods.
240
- ([@azach], [@ixti])
241
-
242
-
243
- ## 0.3.2 (2016-05-16)
244
-
245
- * [#13](https://github.com/sensortower/sidekiq-throttled/issues/13)
246
- Fix throttled BasicFetch with strictly ordered queues on sidekiq 4.
247
- ([@palanglung], [@ixti])
248
-
249
-
250
- ## 0.3.1 (2016-05-15)
251
-
252
- * Precalculate LUA script digests to reduce bandwidth upon nodes reload
253
- _(which might (and might not) happen if you run thousands of nodes)_.
254
- ([@ixti])
255
-
256
-
257
- ## 0.3.0 (2016-05-02)
258
-
259
- * [#1](https://github.com/sensortower/sidekiq-throttled/issues/1):
260
- Add Sidekiq 4.0 support.
261
- ([@ixti])
262
-
263
-
264
- ## 0.2.0 (2016-02-29)
265
-
266
- * [#6](https://github.com/sensortower/sidekiq-throttled/pull/6):
267
- Add dynamic key suffix functionality.
268
- ([@fhwang])
269
-
270
-
271
- ## 0.1.0 (2015-11-03)
272
-
273
- * Initial release.
274
-
275
-
276
- [@ixti]: https://github.com/ixti
277
- [@fhwang]: https://github.com/fhwang
278
- [@palanglung]: https://github.com/palanglung
279
- [@azach]: https://github.com/azach
280
- [@iporsut]: https://github.com/iporsut
281
- [@mstruve]: https://github.com/mstruve
282
- [@ziaulrehman40]: https://github.com/ziaulrehman40
283
- [@ogins57]: https://github.com/ogins57
284
- [@lenon]: https://github.com/lenon
285
- [@vaot]: https://github.com/vaot
286
- [@hmaack]: https://github.com/hmaack
287
- [@holyketzer]: https://github.com/holyketzer
288
- [@hubertjakubiak]: https://github.com/hubertjakubiak
289
- [@kylerippey]: https://github.com/kylerippey
290
- [@khaile]: https://github.com/khaile
291
- [@mattiagiuffrida-st]: https://github.com/mattiagiuffrida-st
292
- [@baptistejub]: https://github.com/baptistejub
293
- [@ybiquitous]: https://github.com/ybiquitous
294
- [@hieuk09]: https://github.com/hieuk09
295
- [@petergoldstein]: https://github.com/petergoldstein
296
- [@dbackeus]: https://github.com/dbackeus
297
- [@holstvoogd]: https://github.com/holstvoogd
298
- [@CHTJonas]: https://github.com/CHTJonas
299
- [@pjungwir]: https://github.com/pjungwir
300
- [@longkt90]: https://github.com/longkt90
data/Gemfile DELETED
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal"
6
- gem "rake"
7
- gem "rspec"
8
- gem "sidekiq"
9
-
10
- group :development do
11
- gem "byebug"
12
- gem "guard", :require => false
13
- gem "guard-rspec", :require => false
14
- gem "guard-rubocop", :require => false
15
- end
16
-
17
- group :test do
18
- gem "apparition"
19
- gem "capybara"
20
- gem "puma"
21
- gem "rack-test"
22
- gem "sinatra"
23
- gem "timecop"
24
- end
25
-
26
- group :lint do
27
- gem "rubocop", :require => false
28
- gem "rubocop-performance", :require => false
29
- gem "rubocop-rake", :require => false
30
- gem "rubocop-rspec", :require => false
31
- end
32
-
33
- # Specify your gem's dependencies in sidekiq-throttled.gemspec
34
- gemspec
data/Guardfile DELETED
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- group :red_green_refactor, :halt_on_fail => true do
4
- guard :rspec, :cmd => "bundle exec rspec --no-profile" do
5
- require "guard/rspec/dsl"
6
- dsl = Guard::RSpec::Dsl.new(self)
7
-
8
- # Feel free to open issues for suggestions and improvements
9
-
10
- # RSpec files
11
- rspec = dsl.rspec
12
- watch(rspec.spec_helper) { rspec.spec_dir }
13
- watch(rspec.spec_support) { rspec.spec_dir }
14
- watch(rspec.spec_files)
15
-
16
- # Ruby files
17
- ruby = dsl.ruby
18
- dsl.watch_spec_files_for(ruby.lib_files)
19
- end
20
-
21
- guard :rubocop, :all_on_start => false do
22
- watch(%r{.+\.rb$})
23
- watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
24
- end
25
- end
data/Rakefile DELETED
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
-
5
- require "rspec/core/rake_task"
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- desc "Run RuboCop"
9
- task :rubocop do
10
- require "rubocop"
11
- result = RuboCop::CLI.new.run([])
12
- abort("RuboCop failed!") if result.nonzero?
13
- end
14
-
15
- namespace :rubocop do
16
- desc "Auto-correct RuboCop offenses"
17
- task :autocorrect do
18
- require "rubocop"
19
- result = RuboCop::CLI.new.run(["--auto-correct"])
20
- abort("RuboCop failed!") if result.nonzero?
21
- end
22
- end
23
-
24
- default_suite = ENV["CI"] ? :spec : %i[spec rubocop]
25
- named_suites = { "rubocop" => :rubocop, "rspec" => :spec }
26
-
27
- task :default => named_suites.fetch(ENV.fetch("SUITE", nil), default_suite)
@@ -1,33 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal"
6
- gem "rake"
7
- gem "rspec"
8
- gem "sidekiq", "~> 6.4.0"
9
-
10
- group :development do
11
- gem "byebug"
12
- gem "guard", require: false
13
- gem "guard-rspec", require: false
14
- gem "guard-rubocop", require: false
15
- end
16
-
17
- group :test do
18
- gem "apparition"
19
- gem "capybara"
20
- gem "puma"
21
- gem "rack-test"
22
- gem "sinatra"
23
- gem "timecop"
24
- end
25
-
26
- group :lint do
27
- gem "rubocop", require: false
28
- gem "rubocop-performance", require: false
29
- gem "rubocop-rake", require: false
30
- gem "rubocop-rspec", require: false
31
- end
32
-
33
- gemspec path: "../"
@@ -1,33 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal"
6
- gem "rake"
7
- gem "rspec"
8
- gem "sidekiq", "~> 6.5.0"
9
-
10
- group :development do
11
- gem "byebug"
12
- gem "guard", require: false
13
- gem "guard-rspec", require: false
14
- gem "guard-rubocop", require: false
15
- end
16
-
17
- group :test do
18
- gem "apparition"
19
- gem "capybara"
20
- gem "puma"
21
- gem "rack-test"
22
- gem "sinatra"
23
- gem "timecop"
24
- end
25
-
26
- group :lint do
27
- gem "rubocop", require: false
28
- gem "rubocop-performance", require: false
29
- gem "rubocop-rake", require: false
30
- gem "rubocop-rspec", require: false
31
- end
32
-
33
- gemspec path: "../"
@@ -1,72 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "fiber"
4
-
5
- require "sidekiq/throttled/communicator/exception_handler"
6
-
7
- module Sidekiq
8
- module Throttled
9
- class Communicator
10
- # Callbacks registry and runner. Runs registered callbacks in dedicated
11
- # Fiber solving issue with ConnectionPool and Redis client in subscriber
12
- # mode.
13
- #
14
- # Once Redis entered subscriber mode `#subscribe` method, it can't be used
15
- # for any command but pub/sub or quit, making it impossible to use for
16
- # anything else. ConnectionPool binds reserved client to Thread, thus
17
- # nested `#with` calls inside same thread result into a same connection.
18
- # That makes it impossible to issue any normal Redis commands from
19
- # within listener Thread.
20
- #
21
- # @private
22
- class Callbacks
23
- include ExceptionHandler
24
-
25
- # Initializes callbacks registry.
26
- def initialize
27
- @mutex = Mutex.new
28
- @handlers = Hash.new { |h, k| h[k] = [] }
29
- end
30
-
31
- # Registers handler of given event.
32
- #
33
- # @example
34
- #
35
- # callbacks.on "and out comes wolves" do |who|
36
- # puts "#{who} let the dogs out?!"
37
- # end
38
- #
39
- # @param [#to_s] event
40
- # @raise [ArgumentError] if no handler block given
41
- # @yield [*args] Runs given block upon `event`
42
- # @yieldreturn [void]
43
- # @return [self]
44
- def on(event, &handler)
45
- raise ArgumentError, "No block given" unless handler
46
-
47
- @mutex.synchronize { @handlers[event.to_s] << handler }
48
- self
49
- end
50
-
51
- # Runs event handlers with given args.
52
- #
53
- # @param [#to_s] event
54
- # @param [Object] payload
55
- # @return [void]
56
- def run(event, payload = nil)
57
- @mutex.synchronize do
58
- fiber = Fiber.new do
59
- @handlers[event.to_s].each do |callback|
60
- callback.call(payload)
61
- rescue => e
62
- handle_exception(e, :context => "sidekiq:throttled")
63
- end
64
- end
65
-
66
- fiber.resume
67
- end
68
- end
69
- end
70
- end
71
- end
72
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "sidekiq"
4
- require "sidekiq/version"
5
-
6
- module Sidekiq
7
- module Throttled
8
- class Communicator
9
- if Sidekiq::VERSION >= "6.5.0"
10
- module ExceptionHandler
11
- def handle_exception(*args)
12
- Sidekiq.handle_exception(*args)
13
- end
14
- end
15
-
16
- # NOTE: `Sidekiq.default_error_handler` is private API
17
- Sidekiq.error_handlers << Sidekiq.method(:default_error_handler)
18
- else
19
- require "sidekiq/exception_handler"
20
-
21
- ExceptionHandler = ::Sidekiq::ExceptionHandler
22
- end
23
- end
24
- end
25
- end
@@ -1,109 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "sidekiq/throttled/communicator/exception_handler"
4
-
5
- module Sidekiq
6
- module Throttled
7
- class Communicator
8
- # Redis subscription listener thread.
9
- #
10
- # @private
11
- class Listener < Thread
12
- include ExceptionHandler
13
-
14
- # Starts listener thread.
15
- #
16
- # @param [String] channel Redis pub/sub channel to listen
17
- # @param [Callbacks] callbacks Message callbacks registry
18
- def initialize(channel, callbacks)
19
- @channel = channel
20
- @callbacks = callbacks
21
- @terminated = false
22
- @subscribed = false
23
-
24
- super { listen until @terminated }
25
- end
26
-
27
- # Whenever underlying redis client subscribed to pub/sup channel.
28
- #
29
- # @return [Boolean]
30
- def ready?
31
- @subscribed
32
- end
33
-
34
- # Whenever main loop is still running.
35
- #
36
- # @return [Boolean]
37
- def listening?
38
- !@terminated
39
- end
40
-
41
- # Stops listener.
42
- #
43
- # @return [void]
44
- def stop
45
- # Raising exception while client is in subscription mode makes
46
- # redis close connection and thus causing ConnectionPool reopen
47
- # it (normal mode). Otherwise subscription mode client will be
48
- # pushed back to ConnectionPool causing problems.
49
- raise Sidekiq::Shutdown
50
- end
51
-
52
- private
53
-
54
- # Wraps {#subscribe} with exception handlers:
55
- #
56
- # - `Sidekiq::Shutdown` exception marks listener as stopped and returns
57
- # making `while` loop of listener thread terminate.
58
- #
59
- # - `StandardError` got recorded to the log and swallowed,
60
- # making `while` loop of the listener thread restart.
61
- #
62
- # - `Exception` is recorded to the log and re-raised.
63
- #
64
- # @return [void]
65
- def listen # rubocop:disable Metrics/MethodLength
66
- subscribe
67
- rescue Sidekiq::Shutdown
68
- @terminated = true
69
- @subscribed = false
70
- rescue StandardError => e # rubocop:disable Style/RescueStandardError
71
- @subscribed = false
72
- handle_exception(e, { :context => "sidekiq:throttled" })
73
- sleep 1
74
- rescue Exception => e # rubocop:disable Lint/RescueException
75
- @terminated = true
76
- @subscribed = false
77
- handle_exception(e, { :context => "sidekiq:throttled" })
78
- raise
79
- end
80
-
81
- # Subscribes to channel and triggers all registerd handlers for
82
- # received messages.
83
- #
84
- # @note Puts thread's Redis connection to subscription mode and
85
- # locks thread.
86
- #
87
- # @see http://redis.io/topics/pubsub
88
- # @see http://redis.io/commands/subscribe
89
- # @see Callbacks#run
90
- # @return [void]
91
- def subscribe # rubocop:disable Metrics/MethodLength
92
- Sidekiq.redis do |conn|
93
- conn.subscribe @channel do |on|
94
- on.subscribe do
95
- @subscribed = true
96
- @callbacks.run("ready")
97
- end
98
-
99
- on.message do |_channel, data|
100
- message, payload = Marshal.load(data) # rubocop:disable Security/MarshalLoad:
101
- @callbacks.run("message:#{message}", payload)
102
- end
103
- end
104
- end
105
- end
106
- end
107
- end
108
- end
109
- end