kicks 3.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ci.yml +24 -0
  3. data/.gitignore +12 -0
  4. data/ChangeLog.md +142 -0
  5. data/Dockerfile +24 -0
  6. data/Dockerfile.slim +20 -0
  7. data/Gemfile +8 -0
  8. data/Guardfile +8 -0
  9. data/LICENSE.txt +22 -0
  10. data/README.md +209 -0
  11. data/Rakefile +12 -0
  12. data/bin/sneakers +6 -0
  13. data/docker-compose.yml +24 -0
  14. data/examples/benchmark_worker.rb +22 -0
  15. data/examples/max_retry_handler.rb +68 -0
  16. data/examples/metrics_worker.rb +34 -0
  17. data/examples/middleware_worker.rb +36 -0
  18. data/examples/newrelic_metrics_worker.rb +40 -0
  19. data/examples/profiling_worker.rb +69 -0
  20. data/examples/sneakers.conf.rb.example +11 -0
  21. data/examples/title_scraper.rb +36 -0
  22. data/examples/workflow_worker.rb +23 -0
  23. data/kicks.gemspec +44 -0
  24. data/lib/sneakers/cli.rb +122 -0
  25. data/lib/sneakers/concerns/logging.rb +34 -0
  26. data/lib/sneakers/concerns/metrics.rb +34 -0
  27. data/lib/sneakers/configuration.rb +125 -0
  28. data/lib/sneakers/content_encoding.rb +47 -0
  29. data/lib/sneakers/content_type.rb +47 -0
  30. data/lib/sneakers/error_reporter.rb +33 -0
  31. data/lib/sneakers/errors.rb +2 -0
  32. data/lib/sneakers/handlers/maxretry.rb +219 -0
  33. data/lib/sneakers/handlers/oneshot.rb +26 -0
  34. data/lib/sneakers/metrics/logging_metrics.rb +16 -0
  35. data/lib/sneakers/metrics/newrelic_metrics.rb +32 -0
  36. data/lib/sneakers/metrics/null_metrics.rb +13 -0
  37. data/lib/sneakers/metrics/statsd_metrics.rb +21 -0
  38. data/lib/sneakers/middleware/config.rb +23 -0
  39. data/lib/sneakers/publisher.rb +49 -0
  40. data/lib/sneakers/queue.rb +87 -0
  41. data/lib/sneakers/runner.rb +91 -0
  42. data/lib/sneakers/spawner.rb +30 -0
  43. data/lib/sneakers/support/production_formatter.rb +11 -0
  44. data/lib/sneakers/support/utils.rb +18 -0
  45. data/lib/sneakers/tasks.rb +66 -0
  46. data/lib/sneakers/version.rb +3 -0
  47. data/lib/sneakers/worker.rb +162 -0
  48. data/lib/sneakers/workergroup.rb +60 -0
  49. data/lib/sneakers.rb +125 -0
  50. data/log/.gitkeep +0 -0
  51. data/scripts/local_integration +2 -0
  52. data/scripts/local_worker +3 -0
  53. data/spec/fixtures/integration_worker.rb +18 -0
  54. data/spec/fixtures/require_worker.rb +23 -0
  55. data/spec/gzip_helper.rb +15 -0
  56. data/spec/sneakers/cli_spec.rb +75 -0
  57. data/spec/sneakers/concerns/logging_spec.rb +39 -0
  58. data/spec/sneakers/concerns/metrics_spec.rb +38 -0
  59. data/spec/sneakers/configuration_spec.rb +97 -0
  60. data/spec/sneakers/content_encoding_spec.rb +81 -0
  61. data/spec/sneakers/content_type_spec.rb +81 -0
  62. data/spec/sneakers/integration_spec.rb +158 -0
  63. data/spec/sneakers/publisher_spec.rb +179 -0
  64. data/spec/sneakers/queue_spec.rb +169 -0
  65. data/spec/sneakers/runner_spec.rb +70 -0
  66. data/spec/sneakers/sneakers_spec.rb +77 -0
  67. data/spec/sneakers/support/utils_spec.rb +44 -0
  68. data/spec/sneakers/tasks/sneakers_run_spec.rb +115 -0
  69. data/spec/sneakers/worker_handlers_spec.rb +469 -0
  70. data/spec/sneakers/worker_spec.rb +712 -0
  71. data/spec/sneakers/workergroup_spec.rb +83 -0
  72. data/spec/spec_helper.rb +21 -0
  73. metadata +352 -0
@@ -0,0 +1,83 @@
1
+ require 'logger'
2
+ require 'spec_helper'
3
+ require 'sneakers'
4
+ require 'sneakers/runner'
5
+
6
+ class DummyFlag
7
+ def wait_for_set(*)
8
+ true
9
+ end
10
+ end
11
+
12
+ class DummyEngine
13
+ include Sneakers::WorkerGroup
14
+
15
+ attr_reader :config
16
+
17
+ def initialize(config)
18
+ @config = config
19
+ @stop_flag = DummyFlag.new
20
+ end
21
+ end
22
+
23
+ class DefaultsWorker
24
+ include Sneakers::Worker
25
+ from_queue 'defaults'
26
+
27
+ def work(msg); end
28
+ end
29
+
30
+ class StubbedWorker
31
+ attr_reader :opts
32
+
33
+ def initialize(_, _, opts)
34
+ @opts = opts
35
+ end
36
+
37
+ def run
38
+ true
39
+ end
40
+ end
41
+
42
+ describe Sneakers::WorkerGroup do
43
+ let(:logger) { Logger.new('log/logtest.log') }
44
+ let(:connection) { Bunny.new(host: 'any-host.local') }
45
+ let(:runner) { Sneakers::Runner.new([DefaultsWorker]) }
46
+ let(:runner_config) { runner.instance_variable_get('@runnerconfig') }
47
+ let(:config) { runner_config.reload_config! }
48
+ let(:engine) { DummyEngine.new(config) }
49
+
50
+ describe '#run' do
51
+ describe 'with connecion provided' do
52
+ before do
53
+ Sneakers.clear!
54
+ Sneakers.configure(connection: connection, log: logger)
55
+ end
56
+
57
+ it 'creates workers with connection: connection' do
58
+ DefaultsWorker.stub(:new, ->(*args) { StubbedWorker.new(*args) }) do
59
+ engine.run
60
+
61
+ workers = engine.instance_variable_get('@workers')
62
+ _(workers.first.opts[:connection]).must_equal(connection)
63
+ end
64
+ end
65
+ end
66
+
67
+ describe 'without connecion provided' do
68
+ before do
69
+ Sneakers.clear!
70
+ Sneakers.configure(log: logger)
71
+ end
72
+
73
+ it 'creates workers with connection: nil' do
74
+ DefaultsWorker.stub(:new, ->(*args) { StubbedWorker.new(*args) }) do
75
+ engine.run
76
+
77
+ workers = engine.instance_variable_get('@workers')
78
+ assert_nil(workers.first.opts[:connection])
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,21 @@
1
+ require 'bundler/setup'
2
+ require 'simplecov'
3
+ require 'resolv'
4
+ require 'pry-byebug'
5
+
6
+ SimpleCov.start do
7
+ add_filter "/spec/"
8
+ end
9
+
10
+ require 'minitest/autorun'
11
+
12
+ require 'rr'
13
+
14
+ def compose_or_localhost(key)
15
+ Resolv::DNS.new.getaddress(key)
16
+ rescue
17
+ "localhost"
18
+ end
19
+
20
+
21
+
metadata ADDED
@@ -0,0 +1,352 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kicks
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0.pre
5
+ platform: ruby
6
+ authors:
7
+ - Dotan Nahum
8
+ - Michael Klishin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2024-06-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: serverengine
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '2.1'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '2.1'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bunny
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '2.19'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '2.19'
42
+ - !ruby/object:Gem::Dependency
43
+ name: concurrent-ruby
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: thor
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '12.3'
77
+ - - "<"
78
+ - !ruby/object:Gem::Version
79
+ version: '14.0'
80
+ type: :runtime
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '12.3'
87
+ - - "<"
88
+ - !ruby/object:Gem::Version
89
+ version: '14.0'
90
+ - !ruby/object:Gem::Dependency
91
+ name: rabbitmq_http_api_client
92
+ requirement: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ type: :development
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ - !ruby/object:Gem::Dependency
105
+ name: redis
106
+ requirement: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ - !ruby/object:Gem::Dependency
119
+ name: minitest
120
+ requirement: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '5.15'
125
+ type: :development
126
+ prerelease: false
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '5.15'
132
+ - !ruby/object:Gem::Dependency
133
+ name: rr
134
+ requirement: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.0'
139
+ type: :development
140
+ prerelease: false
141
+ version_requirements: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '3.0'
146
+ - !ruby/object:Gem::Dependency
147
+ name: unparser
148
+ requirement: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.2'
153
+ type: :development
154
+ prerelease: false
155
+ version_requirements: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.2'
160
+ - !ruby/object:Gem::Dependency
161
+ name: simplecov
162
+ requirement: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.21'
167
+ type: :development
168
+ prerelease: false
169
+ version_requirements: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '0.21'
174
+ - !ruby/object:Gem::Dependency
175
+ name: simplecov-rcov-text
176
+ requirement: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ type: :development
182
+ prerelease: false
183
+ version_requirements: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ - !ruby/object:Gem::Dependency
189
+ name: guard
190
+ requirement: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '2.18'
195
+ type: :development
196
+ prerelease: false
197
+ version_requirements: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: '2.18'
202
+ - !ruby/object:Gem::Dependency
203
+ name: guard-minitest
204
+ requirement: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: '2.4'
209
+ type: :development
210
+ prerelease: false
211
+ version_requirements: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: '2.4'
216
+ - !ruby/object:Gem::Dependency
217
+ name: pry-byebug
218
+ requirement: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: '3.9'
223
+ type: :development
224
+ prerelease: false
225
+ version_requirements: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: '3.9'
230
+ description: " Fast background processing framework for Ruby and RabbitMQ "
231
+ email:
232
+ - michael@clojurewerkz.org
233
+ executables:
234
+ - sneakers
235
+ extensions: []
236
+ extra_rdoc_files: []
237
+ files:
238
+ - ".github/workflows/ci.yml"
239
+ - ".gitignore"
240
+ - ChangeLog.md
241
+ - Dockerfile
242
+ - Dockerfile.slim
243
+ - Gemfile
244
+ - Guardfile
245
+ - LICENSE.txt
246
+ - README.md
247
+ - Rakefile
248
+ - bin/sneakers
249
+ - docker-compose.yml
250
+ - examples/benchmark_worker.rb
251
+ - examples/max_retry_handler.rb
252
+ - examples/metrics_worker.rb
253
+ - examples/middleware_worker.rb
254
+ - examples/newrelic_metrics_worker.rb
255
+ - examples/profiling_worker.rb
256
+ - examples/sneakers.conf.rb.example
257
+ - examples/title_scraper.rb
258
+ - examples/workflow_worker.rb
259
+ - kicks.gemspec
260
+ - lib/sneakers.rb
261
+ - lib/sneakers/cli.rb
262
+ - lib/sneakers/concerns/logging.rb
263
+ - lib/sneakers/concerns/metrics.rb
264
+ - lib/sneakers/configuration.rb
265
+ - lib/sneakers/content_encoding.rb
266
+ - lib/sneakers/content_type.rb
267
+ - lib/sneakers/error_reporter.rb
268
+ - lib/sneakers/errors.rb
269
+ - lib/sneakers/handlers/maxretry.rb
270
+ - lib/sneakers/handlers/oneshot.rb
271
+ - lib/sneakers/metrics/logging_metrics.rb
272
+ - lib/sneakers/metrics/newrelic_metrics.rb
273
+ - lib/sneakers/metrics/null_metrics.rb
274
+ - lib/sneakers/metrics/statsd_metrics.rb
275
+ - lib/sneakers/middleware/config.rb
276
+ - lib/sneakers/publisher.rb
277
+ - lib/sneakers/queue.rb
278
+ - lib/sneakers/runner.rb
279
+ - lib/sneakers/spawner.rb
280
+ - lib/sneakers/support/production_formatter.rb
281
+ - lib/sneakers/support/utils.rb
282
+ - lib/sneakers/tasks.rb
283
+ - lib/sneakers/version.rb
284
+ - lib/sneakers/worker.rb
285
+ - lib/sneakers/workergroup.rb
286
+ - log/.gitkeep
287
+ - scripts/local_integration
288
+ - scripts/local_worker
289
+ - spec/fixtures/integration_worker.rb
290
+ - spec/fixtures/require_worker.rb
291
+ - spec/gzip_helper.rb
292
+ - spec/sneakers/cli_spec.rb
293
+ - spec/sneakers/concerns/logging_spec.rb
294
+ - spec/sneakers/concerns/metrics_spec.rb
295
+ - spec/sneakers/configuration_spec.rb
296
+ - spec/sneakers/content_encoding_spec.rb
297
+ - spec/sneakers/content_type_spec.rb
298
+ - spec/sneakers/integration_spec.rb
299
+ - spec/sneakers/publisher_spec.rb
300
+ - spec/sneakers/queue_spec.rb
301
+ - spec/sneakers/runner_spec.rb
302
+ - spec/sneakers/sneakers_spec.rb
303
+ - spec/sneakers/support/utils_spec.rb
304
+ - spec/sneakers/tasks/sneakers_run_spec.rb
305
+ - spec/sneakers/worker_handlers_spec.rb
306
+ - spec/sneakers/worker_spec.rb
307
+ - spec/sneakers/workergroup_spec.rb
308
+ - spec/spec_helper.rb
309
+ homepage: https://github.com/ruby-amqp/kicks
310
+ licenses:
311
+ - MIT
312
+ metadata: {}
313
+ post_install_message:
314
+ rdoc_options: []
315
+ require_paths:
316
+ - lib
317
+ required_ruby_version: !ruby/object:Gem::Requirement
318
+ requirements:
319
+ - - ">="
320
+ - !ruby/object:Gem::Version
321
+ version: '2.5'
322
+ required_rubygems_version: !ruby/object:Gem::Requirement
323
+ requirements:
324
+ - - ">="
325
+ - !ruby/object:Gem::Version
326
+ version: '0'
327
+ requirements: []
328
+ rubygems_version: 3.5.11
329
+ signing_key:
330
+ specification_version: 4
331
+ summary: Fast background processing framework for Ruby and RabbitMQ
332
+ test_files:
333
+ - spec/fixtures/integration_worker.rb
334
+ - spec/fixtures/require_worker.rb
335
+ - spec/gzip_helper.rb
336
+ - spec/sneakers/cli_spec.rb
337
+ - spec/sneakers/concerns/logging_spec.rb
338
+ - spec/sneakers/concerns/metrics_spec.rb
339
+ - spec/sneakers/configuration_spec.rb
340
+ - spec/sneakers/content_encoding_spec.rb
341
+ - spec/sneakers/content_type_spec.rb
342
+ - spec/sneakers/integration_spec.rb
343
+ - spec/sneakers/publisher_spec.rb
344
+ - spec/sneakers/queue_spec.rb
345
+ - spec/sneakers/runner_spec.rb
346
+ - spec/sneakers/sneakers_spec.rb
347
+ - spec/sneakers/support/utils_spec.rb
348
+ - spec/sneakers/tasks/sneakers_run_spec.rb
349
+ - spec/sneakers/worker_handlers_spec.rb
350
+ - spec/sneakers/worker_spec.rb
351
+ - spec/sneakers/workergroup_spec.rb
352
+ - spec/spec_helper.rb