service_skeleton 0.0.0.1.ENOTAG

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +7 -0
  3. data/.git-blame-ignore-revs +2 -0
  4. data/.github/workflows/ci.yml +50 -0
  5. data/.gitignore +9 -0
  6. data/.rubocop.yml +11 -0
  7. data/.yardopts +1 -0
  8. data/CODE_OF_CONDUCT.md +49 -0
  9. data/CONTRIBUTING.md +13 -0
  10. data/LICENCE +674 -0
  11. data/README.md +767 -0
  12. data/lib/service_skeleton.rb +41 -0
  13. data/lib/service_skeleton/config.rb +140 -0
  14. data/lib/service_skeleton/config_class.rb +16 -0
  15. data/lib/service_skeleton/config_variable.rb +44 -0
  16. data/lib/service_skeleton/config_variable/boolean.rb +21 -0
  17. data/lib/service_skeleton/config_variable/enum.rb +27 -0
  18. data/lib/service_skeleton/config_variable/float.rb +25 -0
  19. data/lib/service_skeleton/config_variable/integer.rb +25 -0
  20. data/lib/service_skeleton/config_variable/kv_list.rb +26 -0
  21. data/lib/service_skeleton/config_variable/path_list.rb +13 -0
  22. data/lib/service_skeleton/config_variable/string.rb +18 -0
  23. data/lib/service_skeleton/config_variable/url.rb +36 -0
  24. data/lib/service_skeleton/config_variable/yaml_file.rb +42 -0
  25. data/lib/service_skeleton/config_variables.rb +79 -0
  26. data/lib/service_skeleton/error.rb +10 -0
  27. data/lib/service_skeleton/filtering_logger.rb +38 -0
  28. data/lib/service_skeleton/generator.rb +165 -0
  29. data/lib/service_skeleton/logging_helpers.rb +28 -0
  30. data/lib/service_skeleton/metric_method_name.rb +9 -0
  31. data/lib/service_skeleton/metrics_methods.rb +37 -0
  32. data/lib/service_skeleton/runner.rb +46 -0
  33. data/lib/service_skeleton/service_name.rb +20 -0
  34. data/lib/service_skeleton/signal_manager.rb +202 -0
  35. data/lib/service_skeleton/signals_methods.rb +15 -0
  36. data/lib/service_skeleton/ultravisor_children.rb +20 -0
  37. data/lib/service_skeleton/ultravisor_loggerstash.rb +11 -0
  38. data/service_skeleton.gemspec +54 -0
  39. data/ultravisor/.yardopts +1 -0
  40. data/ultravisor/Guardfile +9 -0
  41. data/ultravisor/README.md +404 -0
  42. data/ultravisor/lib/ultravisor.rb +216 -0
  43. data/ultravisor/lib/ultravisor/child.rb +481 -0
  44. data/ultravisor/lib/ultravisor/child/call.rb +21 -0
  45. data/ultravisor/lib/ultravisor/child/call_receiver.rb +14 -0
  46. data/ultravisor/lib/ultravisor/child/cast.rb +16 -0
  47. data/ultravisor/lib/ultravisor/child/cast_receiver.rb +11 -0
  48. data/ultravisor/lib/ultravisor/child/process_cast_call.rb +39 -0
  49. data/ultravisor/lib/ultravisor/error.rb +25 -0
  50. data/ultravisor/lib/ultravisor/logging_helpers.rb +32 -0
  51. data/ultravisor/spec/example_group_methods.rb +19 -0
  52. data/ultravisor/spec/example_methods.rb +8 -0
  53. data/ultravisor/spec/spec_helper.rb +52 -0
  54. data/ultravisor/spec/ultravisor/add_child_spec.rb +79 -0
  55. data/ultravisor/spec/ultravisor/child/call_spec.rb +121 -0
  56. data/ultravisor/spec/ultravisor/child/cast_spec.rb +111 -0
  57. data/ultravisor/spec/ultravisor/child/id_spec.rb +21 -0
  58. data/ultravisor/spec/ultravisor/child/new_spec.rb +152 -0
  59. data/ultravisor/spec/ultravisor/child/restart_delay_spec.rb +40 -0
  60. data/ultravisor/spec/ultravisor/child/restart_spec.rb +70 -0
  61. data/ultravisor/spec/ultravisor/child/run_spec.rb +95 -0
  62. data/ultravisor/spec/ultravisor/child/shutdown_spec.rb +124 -0
  63. data/ultravisor/spec/ultravisor/child/spawn_spec.rb +107 -0
  64. data/ultravisor/spec/ultravisor/child/unsafe_instance_spec.rb +55 -0
  65. data/ultravisor/spec/ultravisor/child/wait_spec.rb +32 -0
  66. data/ultravisor/spec/ultravisor/new_spec.rb +71 -0
  67. data/ultravisor/spec/ultravisor/remove_child_spec.rb +49 -0
  68. data/ultravisor/spec/ultravisor/run_spec.rb +334 -0
  69. data/ultravisor/spec/ultravisor/shutdown_spec.rb +106 -0
  70. metadata +375 -0
@@ -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 ADDED
@@ -0,0 +1,375 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: service_skeleton
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0.1.ENOTAG
5
+ platform: ruby
6
+ authors:
7
+ - Matt Palmer
8
+ - Sam Saffron
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2021-02-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: frankenstein
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '2.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '2.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: loggerstash
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 0.0.9
35
+ - - "<"
36
+ - !ruby/object:Gem::Version
37
+ version: '1'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 0.0.9
45
+ - - "<"
46
+ - !ruby/object:Gem::Version
47
+ version: '1'
48
+ - !ruby/object:Gem::Dependency
49
+ name: prometheus-client
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: sigdump
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.2'
69
+ type: :runtime
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.2'
76
+ - !ruby/object:Gem::Dependency
77
+ name: to_regexp
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.2'
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.2'
90
+ - !ruby/object:Gem::Dependency
91
+ name: bundler
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: github-release
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: git-version-bump
120
+ requirement: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ type: :development
126
+ prerelease: false
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ - !ruby/object:Gem::Dependency
133
+ name: guard-rspec
134
+ requirement: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ type: :development
140
+ prerelease: false
141
+ version_requirements: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ - !ruby/object:Gem::Dependency
147
+ name: guard-rubocop
148
+ requirement: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ type: :development
154
+ prerelease: false
155
+ version_requirements: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ - !ruby/object:Gem::Dependency
161
+ name: rack-test
162
+ requirement: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ type: :development
168
+ prerelease: false
169
+ version_requirements: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ - !ruby/object:Gem::Dependency
175
+ name: rake
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: redcarpet
190
+ requirement: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ type: :development
196
+ prerelease: false
197
+ version_requirements: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ - !ruby/object:Gem::Dependency
203
+ name: rspec
204
+ requirement: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ type: :development
210
+ prerelease: false
211
+ version_requirements: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ - !ruby/object:Gem::Dependency
217
+ name: rubocop
218
+ requirement: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ type: :development
224
+ prerelease: false
225
+ version_requirements: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ - !ruby/object:Gem::Dependency
231
+ name: rubocop-discourse
232
+ requirement: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ type: :development
238
+ prerelease: false
239
+ version_requirements: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ - !ruby/object:Gem::Dependency
245
+ name: simplecov
246
+ requirement: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ type: :development
252
+ prerelease: false
253
+ version_requirements: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ version: '0'
258
+ - !ruby/object:Gem::Dependency
259
+ name: yard
260
+ requirement: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - ">="
263
+ - !ruby/object:Gem::Version
264
+ version: '0'
265
+ type: :development
266
+ prerelease: false
267
+ version_requirements: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - ">="
270
+ - !ruby/object:Gem::Version
271
+ version: '0'
272
+ description: |
273
+ When you need to write a program that provides some sort of persistent
274
+ service, there are some things you always need. Logging, metrics,
275
+ extracting configuration from the environment, signal handling, and so on.
276
+ This gem provides ServiceSkeleton, a template class you can use as a base
277
+ for your services, as well as a collection of helper classes to manage
278
+ common aspects of a system service.
279
+ email:
280
+ - sam.saffron@discourse.org
281
+ executables: []
282
+ extensions: []
283
+ extra_rdoc_files: []
284
+ files:
285
+ - ".editorconfig"
286
+ - ".git-blame-ignore-revs"
287
+ - ".github/workflows/ci.yml"
288
+ - ".gitignore"
289
+ - ".rubocop.yml"
290
+ - ".yardopts"
291
+ - CODE_OF_CONDUCT.md
292
+ - CONTRIBUTING.md
293
+ - LICENCE
294
+ - README.md
295
+ - lib/service_skeleton.rb
296
+ - lib/service_skeleton/config.rb
297
+ - lib/service_skeleton/config_class.rb
298
+ - lib/service_skeleton/config_variable.rb
299
+ - lib/service_skeleton/config_variable/boolean.rb
300
+ - lib/service_skeleton/config_variable/enum.rb
301
+ - lib/service_skeleton/config_variable/float.rb
302
+ - lib/service_skeleton/config_variable/integer.rb
303
+ - lib/service_skeleton/config_variable/kv_list.rb
304
+ - lib/service_skeleton/config_variable/path_list.rb
305
+ - lib/service_skeleton/config_variable/string.rb
306
+ - lib/service_skeleton/config_variable/url.rb
307
+ - lib/service_skeleton/config_variable/yaml_file.rb
308
+ - lib/service_skeleton/config_variables.rb
309
+ - lib/service_skeleton/error.rb
310
+ - lib/service_skeleton/filtering_logger.rb
311
+ - lib/service_skeleton/generator.rb
312
+ - lib/service_skeleton/logging_helpers.rb
313
+ - lib/service_skeleton/metric_method_name.rb
314
+ - lib/service_skeleton/metrics_methods.rb
315
+ - lib/service_skeleton/runner.rb
316
+ - lib/service_skeleton/service_name.rb
317
+ - lib/service_skeleton/signal_manager.rb
318
+ - lib/service_skeleton/signals_methods.rb
319
+ - lib/service_skeleton/ultravisor_children.rb
320
+ - lib/service_skeleton/ultravisor_loggerstash.rb
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
353
+ homepage: https://github.com/discourse/service_skeleton
354
+ licenses: []
355
+ metadata: {}
356
+ post_install_message:
357
+ rdoc_options: []
358
+ require_paths:
359
+ - lib
360
+ required_ruby_version: !ruby/object:Gem::Requirement
361
+ requirements:
362
+ - - ">="
363
+ - !ruby/object:Gem::Version
364
+ version: 2.5.0
365
+ required_rubygems_version: !ruby/object:Gem::Requirement
366
+ requirements:
367
+ - - ">"
368
+ - !ruby/object:Gem::Version
369
+ version: 1.3.1
370
+ requirements: []
371
+ rubygems_version: 3.0.3
372
+ signing_key:
373
+ specification_version: 4
374
+ summary: The bare bones of a service
375
+ test_files: []