service_skeleton 0.0.0.48.g4a40599 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.git-blame-ignore-revs +2 -0
  3. data/.github/workflows/ci.yml +52 -0
  4. data/.rubocop.yml +11 -1
  5. data/README.md +6 -6
  6. data/lib/service_skeleton/config.rb +20 -13
  7. data/lib/service_skeleton/generator.rb +5 -5
  8. data/lib/service_skeleton/runner.rb +3 -3
  9. data/lib/service_skeleton/ultravisor_children.rb +4 -1
  10. data/service_skeleton.gemspec +4 -5
  11. data/ultravisor/.yardopts +1 -0
  12. data/ultravisor/Guardfile +9 -0
  13. data/ultravisor/README.md +404 -0
  14. data/ultravisor/lib/ultravisor.rb +216 -0
  15. data/ultravisor/lib/ultravisor/child.rb +481 -0
  16. data/ultravisor/lib/ultravisor/child/call.rb +21 -0
  17. data/ultravisor/lib/ultravisor/child/call_receiver.rb +14 -0
  18. data/ultravisor/lib/ultravisor/child/cast.rb +16 -0
  19. data/ultravisor/lib/ultravisor/child/cast_receiver.rb +11 -0
  20. data/ultravisor/lib/ultravisor/child/process_cast_call.rb +39 -0
  21. data/ultravisor/lib/ultravisor/error.rb +25 -0
  22. data/ultravisor/lib/ultravisor/logging_helpers.rb +32 -0
  23. data/ultravisor/spec/example_group_methods.rb +19 -0
  24. data/ultravisor/spec/example_methods.rb +8 -0
  25. data/ultravisor/spec/spec_helper.rb +52 -0
  26. data/ultravisor/spec/ultravisor/add_child_spec.rb +79 -0
  27. data/ultravisor/spec/ultravisor/child/call_spec.rb +121 -0
  28. data/ultravisor/spec/ultravisor/child/cast_spec.rb +111 -0
  29. data/ultravisor/spec/ultravisor/child/id_spec.rb +21 -0
  30. data/ultravisor/spec/ultravisor/child/new_spec.rb +152 -0
  31. data/ultravisor/spec/ultravisor/child/restart_delay_spec.rb +40 -0
  32. data/ultravisor/spec/ultravisor/child/restart_spec.rb +70 -0
  33. data/ultravisor/spec/ultravisor/child/run_spec.rb +95 -0
  34. data/ultravisor/spec/ultravisor/child/shutdown_spec.rb +124 -0
  35. data/ultravisor/spec/ultravisor/child/spawn_spec.rb +107 -0
  36. data/ultravisor/spec/ultravisor/child/unsafe_instance_spec.rb +55 -0
  37. data/ultravisor/spec/ultravisor/child/wait_spec.rb +32 -0
  38. data/ultravisor/spec/ultravisor/new_spec.rb +71 -0
  39. data/ultravisor/spec/ultravisor/remove_child_spec.rb +49 -0
  40. data/ultravisor/spec/ultravisor/run_spec.rb +334 -0
  41. data/ultravisor/spec/ultravisor/shutdown_spec.rb +106 -0
  42. metadata +51 -32
  43. data/.travis.yml +0 -11
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+ require_relative "../spec_helper"
3
+
4
+ require_relative "../../lib/ultravisor"
5
+
6
+ describe Ultravisor do
7
+ let(:args) { {} }
8
+ let(:ultravisor) { Ultravisor.new(**args) }
9
+ let(:mock_thread) { instance_double(Thread) }
10
+
11
+ describe "#shutdown" do
12
+ it "takes the @op_m lock" do
13
+ expect(ultravisor.instance_variable_get(:@op_m)).to receive(:synchronize).and_call_original
14
+
15
+ ultravisor.shutdown
16
+ end
17
+
18
+ context "when the ultravisor isn't running" do
19
+ it "returns itself" do
20
+ expect(ultravisor.shutdown).to eq(ultravisor)
21
+ end
22
+ end
23
+
24
+ context "when the ultravisor is running" do
25
+ before(:each) do
26
+ ultravisor.instance_variable_set(:@running_thread, mock_thread)
27
+ allow(ultravisor.instance_variable_get(:@op_cv))
28
+ .to receive(:wait) do
29
+ ultravisor.instance_variable_set(:@running_thread, nil)
30
+ end
31
+ end
32
+
33
+ it "signals the ultravisor to shutdown" do
34
+ expect(ultravisor.instance_variable_get(:@queue)).to receive(:<<).with(:shutdown)
35
+
36
+ ultravisor.shutdown
37
+ end
38
+
39
+ it "waits until the CV is signalled" do
40
+ expect(ultravisor.instance_variable_get(:@op_cv)).to receive(:wait) do |m|
41
+ expect(m).to eq(ultravisor.instance_variable_get(:@op_m))
42
+ ultravisor.instance_variable_set(:@running_thread, nil)
43
+ nil
44
+ end
45
+
46
+ ultravisor.shutdown
47
+ end
48
+
49
+ context "when asked to not wait" do
50
+ it "doesn't wait on the CV" do
51
+ expect(ultravisor.instance_variable_get(:@op_cv)).to_not receive(:wait)
52
+
53
+ ultravisor.shutdown(wait: false)
54
+ end
55
+ end
56
+
57
+ it "returns itself" do
58
+ expect(ultravisor.shutdown).to eq(ultravisor)
59
+ end
60
+
61
+ context "when forced" do
62
+ before(:each) do
63
+ allow(mock_thread).to receive(:kill)
64
+ end
65
+
66
+ it "kills the thread" do
67
+ expect(mock_thread).to receive(:kill)
68
+
69
+ ultravisor.shutdown(force: true)
70
+ end
71
+
72
+ it "tells everyone waiting for the shutdown that the deed is done" do
73
+ expect(ultravisor.instance_variable_get(:@op_cv)).to receive(:broadcast)
74
+
75
+ ultravisor.shutdown(force: true)
76
+ end
77
+
78
+ it "unsets the running thread" do
79
+ ultravisor.shutdown(force: true)
80
+
81
+ expect(ultravisor.instance_variable_get(:@running_thread)).to be(nil)
82
+ end
83
+
84
+ it "doesn't wait on the CV" do
85
+ expect(ultravisor.instance_variable_get(:@op_cv)).to_not receive(:wait)
86
+
87
+ ultravisor.shutdown(force: true)
88
+ end
89
+
90
+ context "with children" do
91
+ let(:child) { Ultravisor::Child.new(id: :one, klass: Object, method: :to_s) }
92
+
93
+ before(:each) do
94
+ ultravisor.instance_variable_set(:@children, [[:child, child]])
95
+ end
96
+
97
+ it "forcibly shuts down the children" do
98
+ expect(child).to receive(:shutdown).with(force: true)
99
+
100
+ ultravisor.shutdown(force: true)
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: service_skeleton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.48.g4a40599
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Palmer
8
- autorequire:
8
+ - Sam Saffron
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2020-06-01 00:00:00.000000000 Z
12
+ date: 2021-02-01 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: frankenstein
@@ -86,20 +87,6 @@ dependencies:
86
87
  - - "~>"
87
88
  - !ruby/object:Gem::Version
88
89
  version: '0.2'
89
- - !ruby/object:Gem::Dependency
90
- name: ultravisor
91
- requirement: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - "~>"
94
- - !ruby/object:Gem::Version
95
- version: 0.a
96
- type: :runtime
97
- prerelease: false
98
- version_requirements: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - "~>"
101
- - !ruby/object:Gem::Version
102
- version: 0.a
103
90
  - !ruby/object:Gem::Dependency
104
91
  name: bundler
105
92
  requirement: !ruby/object:Gem::Requirement
@@ -188,16 +175,16 @@ dependencies:
188
175
  name: rake
189
176
  requirement: !ruby/object:Gem::Requirement
190
177
  requirements:
191
- - - "~>"
178
+ - - ">="
192
179
  - !ruby/object:Gem::Version
193
- version: '12.0'
180
+ version: '0'
194
181
  type: :development
195
182
  prerelease: false
196
183
  version_requirements: !ruby/object:Gem::Requirement
197
184
  requirements:
198
- - - "~>"
185
+ - - ">="
199
186
  - !ruby/object:Gem::Version
200
- version: '12.0'
187
+ version: '0'
201
188
  - !ruby/object:Gem::Dependency
202
189
  name: redcarpet
203
190
  requirement: !ruby/object:Gem::Requirement
@@ -230,16 +217,16 @@ dependencies:
230
217
  name: rubocop
231
218
  requirement: !ruby/object:Gem::Requirement
232
219
  requirements:
233
- - - "~>"
220
+ - - ">="
234
221
  - !ruby/object:Gem::Version
235
- version: '0.79'
222
+ version: '0'
236
223
  type: :development
237
224
  prerelease: false
238
225
  version_requirements: !ruby/object:Gem::Requirement
239
226
  requirements:
240
- - - "~>"
227
+ - - ">="
241
228
  - !ruby/object:Gem::Version
242
- version: '0.79'
229
+ version: '0'
243
230
  - !ruby/object:Gem::Dependency
244
231
  name: rubocop-discourse
245
232
  requirement: !ruby/object:Gem::Requirement
@@ -290,15 +277,16 @@ description: |
290
277
  for your services, as well as a collection of helper classes to manage
291
278
  common aspects of a system service.
292
279
  email:
293
- - matt.palmer@discourse.org
280
+ - sam.saffron@discourse.org
294
281
  executables: []
295
282
  extensions: []
296
283
  extra_rdoc_files: []
297
284
  files:
298
285
  - ".editorconfig"
286
+ - ".git-blame-ignore-revs"
287
+ - ".github/workflows/ci.yml"
299
288
  - ".gitignore"
300
289
  - ".rubocop.yml"
301
- - ".travis.yml"
302
290
  - ".yardopts"
303
291
  - CODE_OF_CONDUCT.md
304
292
  - CONTRIBUTING.md
@@ -331,10 +319,41 @@ files:
331
319
  - lib/service_skeleton/ultravisor_children.rb
332
320
  - lib/service_skeleton/ultravisor_loggerstash.rb
333
321
  - service_skeleton.gemspec
322
+ - ultravisor/.yardopts
323
+ - ultravisor/Guardfile
324
+ - ultravisor/README.md
325
+ - ultravisor/lib/ultravisor.rb
326
+ - ultravisor/lib/ultravisor/child.rb
327
+ - ultravisor/lib/ultravisor/child/call.rb
328
+ - ultravisor/lib/ultravisor/child/call_receiver.rb
329
+ - ultravisor/lib/ultravisor/child/cast.rb
330
+ - ultravisor/lib/ultravisor/child/cast_receiver.rb
331
+ - ultravisor/lib/ultravisor/child/process_cast_call.rb
332
+ - ultravisor/lib/ultravisor/error.rb
333
+ - ultravisor/lib/ultravisor/logging_helpers.rb
334
+ - ultravisor/spec/example_group_methods.rb
335
+ - ultravisor/spec/example_methods.rb
336
+ - ultravisor/spec/spec_helper.rb
337
+ - ultravisor/spec/ultravisor/add_child_spec.rb
338
+ - ultravisor/spec/ultravisor/child/call_spec.rb
339
+ - ultravisor/spec/ultravisor/child/cast_spec.rb
340
+ - ultravisor/spec/ultravisor/child/id_spec.rb
341
+ - ultravisor/spec/ultravisor/child/new_spec.rb
342
+ - ultravisor/spec/ultravisor/child/restart_delay_spec.rb
343
+ - ultravisor/spec/ultravisor/child/restart_spec.rb
344
+ - ultravisor/spec/ultravisor/child/run_spec.rb
345
+ - ultravisor/spec/ultravisor/child/shutdown_spec.rb
346
+ - ultravisor/spec/ultravisor/child/spawn_spec.rb
347
+ - ultravisor/spec/ultravisor/child/unsafe_instance_spec.rb
348
+ - ultravisor/spec/ultravisor/child/wait_spec.rb
349
+ - ultravisor/spec/ultravisor/new_spec.rb
350
+ - ultravisor/spec/ultravisor/remove_child_spec.rb
351
+ - ultravisor/spec/ultravisor/run_spec.rb
352
+ - ultravisor/spec/ultravisor/shutdown_spec.rb
334
353
  homepage: https://github.com/discourse/service_skeleton
335
354
  licenses: []
336
355
  metadata: {}
337
- post_install_message:
356
+ post_install_message:
338
357
  rdoc_options: []
339
358
  require_paths:
340
359
  - lib
@@ -345,12 +364,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
345
364
  version: 2.5.0
346
365
  required_rubygems_version: !ruby/object:Gem::Requirement
347
366
  requirements:
348
- - - ">"
367
+ - - ">="
349
368
  - !ruby/object:Gem::Version
350
- version: 1.3.1
369
+ version: '0'
351
370
  requirements: []
352
- rubygems_version: 3.0.3
353
- signing_key:
371
+ rubygems_version: 3.1.4
372
+ signing_key:
354
373
  specification_version: 4
355
374
  summary: The bare bones of a service
356
375
  test_files: []
data/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- cache: bundler
4
-
5
- rvm:
6
- - 2.5.3
7
- - 2.4.5
8
- - 2.3.8
9
-
10
- gemfile:
11
- - Gemfile