service_skeleton 0.0.0.2.g46c1e0e → 0.0.0.3.g1269800
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/service_skeleton.rb +31 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54f7ce2f282a5da9818948a40ec390c7c5cb13f0
|
4
|
+
data.tar.gz: 83fa2415988d4c7ec93098be26424cbd73dc5ee3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81fb4b71d9a0c17264dc11721df78b720d35e0fbdcc9c8ece31c223571d72e3f9c825fe96ef5c4c0ed8877b11d86bef9c0132c9557f963f5aa8a6b559b10b920
|
7
|
+
data.tar.gz: ec0db152836431cf3891de6802fda44b0dc4816f352fae76a897059f15badf7bc98f1f468e5b44942846c0489a8e3816dbcfdeed506abe5af71b3d83605b1df9
|
data/lib/service_skeleton.rb
CHANGED
@@ -16,6 +16,8 @@ class ServiceSkeleton
|
|
16
16
|
|
17
17
|
include ServiceSkeleton::LoggingHelpers
|
18
18
|
|
19
|
+
class Terminate < Exception; end
|
20
|
+
|
19
21
|
def self.config_class(klass)
|
20
22
|
@config_class = klass
|
21
23
|
end
|
@@ -31,29 +33,44 @@ class ServiceSkeleton
|
|
31
33
|
attr_reader :config, :metrics, :logger
|
32
34
|
|
33
35
|
def initialize(env)
|
34
|
-
@env
|
35
|
-
@config
|
36
|
-
@logger
|
36
|
+
@env = env
|
37
|
+
@config = (self.class.instance_variable_get(:@config_class) || ServiceSkeleton::Config).new(env, self)
|
38
|
+
@logger = @config.logger
|
39
|
+
@op_mutex = Mutex.new
|
37
40
|
|
38
41
|
setup_metrics
|
39
42
|
setup_signals
|
40
43
|
end
|
41
44
|
|
42
45
|
def start
|
46
|
+
@op_mutex.synchronize { @thread = Thread.current }
|
47
|
+
|
43
48
|
begin
|
44
49
|
start_metrics_server
|
45
50
|
start_signal_handler
|
46
51
|
run
|
52
|
+
rescue ServiceSkeleton::Terminate
|
53
|
+
# This one is OK
|
47
54
|
rescue ServiceSkeleton::Error::InheritanceContractError
|
48
55
|
# We want this one to be fatal
|
49
56
|
raise
|
50
57
|
rescue StandardError => ex
|
51
58
|
log_exception(ex)
|
52
59
|
end
|
60
|
+
|
61
|
+
@thread = nil
|
53
62
|
end
|
54
63
|
|
55
64
|
def stop(force = false)
|
56
|
-
|
65
|
+
if force
|
66
|
+
@op_mutex.synchronize do
|
67
|
+
if @thread
|
68
|
+
@thread.raise(ServiceSkeleton::Terminate)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
else
|
72
|
+
shutdown
|
73
|
+
end
|
57
74
|
|
58
75
|
if @metrics_server
|
59
76
|
@metrics_server.shutdown
|
@@ -81,6 +98,16 @@ class ServiceSkeleton
|
|
81
98
|
raise ServiceSkeleton::Error::InheritanceContractError, "ServiceSkeleton#run method not overridden"
|
82
99
|
end
|
83
100
|
|
101
|
+
def shutdown
|
102
|
+
@op_mutex.synchronize do
|
103
|
+
if @thread
|
104
|
+
@thread.raise(ServiceSkeleton::Terminate)
|
105
|
+
@thread.join
|
106
|
+
@thread = nil
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
84
111
|
def setup_metrics
|
85
112
|
@metrics = Prometheus::Client::Registry.new
|
86
113
|
|