service_skeleton 2.0.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/service_skeleton/hurriable_timer.rb +61 -0
- data/lib/service_skeleton/hurriable_timer_sequence.rb +35 -0
- data/lib/service_skeleton.rb +2 -0
- data/service_skeleton.gemspec +1 -1
- data/ultravisor/spec/spec_helper.rb +4 -2
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2eb043ee79208c4b1b457b1b9deb2b5901119339c9789d8a6d511870bc038e46
|
4
|
+
data.tar.gz: 6848edcb6fe369e5a6ce0dcf823780ee8047f8953b40ea261e03aa0f47314d27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43fe6a4e0ad9adb50cd78c09c41063df614a0116c194283710660b24f2877994038bb818e35ad78eb7b72da62c3ec7e75646fc2bfae5c6f85ef5fdd7a5289dba
|
7
|
+
data.tar.gz: 9aacd383f2d867a51b19adc8c1d501ad383497d13a72de0b8fa9992301b029cd23e60aaa3c72511e98f240ed060dd1dab6b8b38a89a9de3cce19a40c8c696f39
|
data/README.md
CHANGED
@@ -268,7 +268,7 @@ default for a config variable, like so:
|
|
268
268
|
class GenericHelloService
|
269
269
|
include ServiceSkeleton
|
270
270
|
|
271
|
-
string :RECIPIENT, match: /\
|
271
|
+
string :RECIPIENT, match: /\A\w+\z/, default: "Anonymous Coward"
|
272
272
|
|
273
273
|
# ...
|
274
274
|
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# A mechanism for waiting until a timer expires or until another thread signals
|
4
|
+
# readiness.
|
5
|
+
class ServiceSkeleton::HurriableTimer
|
6
|
+
def initialize(timeout)
|
7
|
+
@mutex = Mutex.new
|
8
|
+
@condition = ConditionVariable.new
|
9
|
+
@end_time = now + timeout
|
10
|
+
@hurried = false
|
11
|
+
end
|
12
|
+
|
13
|
+
# Wait for the timer to elapse
|
14
|
+
#
|
15
|
+
# Any number of threads can wait on the same HurriableTimer
|
16
|
+
def wait(t = nil)
|
17
|
+
end_time =
|
18
|
+
if t
|
19
|
+
[@end_time, now + t].min
|
20
|
+
else
|
21
|
+
@end_time
|
22
|
+
end
|
23
|
+
|
24
|
+
@mutex.synchronize {
|
25
|
+
while true
|
26
|
+
remaining = end_time - now
|
27
|
+
|
28
|
+
if remaining < 0 || @hurried
|
29
|
+
break
|
30
|
+
else
|
31
|
+
@condition.wait(@mutex, remaining)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
}
|
35
|
+
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
|
39
|
+
# Cause the timer to trigger early if it hasn't already expired
|
40
|
+
#
|
41
|
+
# This method is idempotent
|
42
|
+
def hurry!
|
43
|
+
@mutex.synchronize {
|
44
|
+
@hurried = true
|
45
|
+
@condition.broadcast
|
46
|
+
}
|
47
|
+
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
|
51
|
+
def expired?
|
52
|
+
@hurried || @end_time - now < 0
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def now
|
58
|
+
# Using this instead of Time.now, because it isn't affected by NTP updates
|
59
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC_RAW)
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# HurribleTimerSequence is a resettable version of HurriableTimer, designed for
|
4
|
+
# cases where some action needs to happen at at least some frequency, but may
|
5
|
+
# happen more often when other threads trigger the process early.
|
6
|
+
#
|
7
|
+
# It would have been possible to implement this without requiring allocation on
|
8
|
+
# reset, by reusing the mutex and condition variable in the normal timer, but
|
9
|
+
# this version is more obviously correct.
|
10
|
+
class ServiceSkeleton::HurriableTimerSequence
|
11
|
+
def initialize(timeout)
|
12
|
+
@mutex = Mutex.new
|
13
|
+
@timeout = timeout
|
14
|
+
@latest = ServiceSkeleton::HurriableTimer.new(@timeout)
|
15
|
+
end
|
16
|
+
|
17
|
+
def reset!
|
18
|
+
@mutex.synchronize {
|
19
|
+
@latest.hurry!
|
20
|
+
@latest = ServiceSkeleton::HurriableTimer.new(@timeout)
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def wait(t = nil)
|
25
|
+
@mutex.synchronize { @latest }.wait(t)
|
26
|
+
end
|
27
|
+
|
28
|
+
def hurry!
|
29
|
+
@mutex.synchronize { @latest }.hurry!
|
30
|
+
end
|
31
|
+
|
32
|
+
def expired?
|
33
|
+
@mutex.synchronize { @latest }.expired?
|
34
|
+
end
|
35
|
+
end
|
data/lib/service_skeleton.rb
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
require_relative "service_skeleton/config_class"
|
4
4
|
require_relative "service_skeleton/config_variables"
|
5
5
|
require_relative "service_skeleton/generator"
|
6
|
+
require_relative "service_skeleton/hurriable_timer"
|
7
|
+
require_relative "service_skeleton/hurriable_timer_sequence"
|
6
8
|
require_relative "service_skeleton/logging_helpers"
|
7
9
|
require_relative "service_skeleton/metrics_methods"
|
8
10
|
require_relative "service_skeleton/service_name"
|
data/service_skeleton.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: service_skeleton
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Palmer
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-01-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: frankenstein
|
@@ -275,6 +275,8 @@ files:
|
|
275
275
|
- lib/service_skeleton/error.rb
|
276
276
|
- lib/service_skeleton/filtering_logger.rb
|
277
277
|
- lib/service_skeleton/generator.rb
|
278
|
+
- lib/service_skeleton/hurriable_timer.rb
|
279
|
+
- lib/service_skeleton/hurriable_timer_sequence.rb
|
278
280
|
- lib/service_skeleton/logging_helpers.rb
|
279
281
|
- lib/service_skeleton/metric_method_name.rb
|
280
282
|
- lib/service_skeleton/metrics_methods.rb
|
@@ -334,7 +336,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
334
336
|
- !ruby/object:Gem::Version
|
335
337
|
version: '0'
|
336
338
|
requirements: []
|
337
|
-
rubygems_version: 3.1.
|
339
|
+
rubygems_version: 3.1.6
|
338
340
|
signing_key:
|
339
341
|
specification_version: 4
|
340
342
|
summary: The bare bones of a service
|