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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/service_skeleton.rb +31 -4
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed4f92117648407bc8af28119fe5fa904950718b
4
- data.tar.gz: 7db90b0421844b8c24a44b63f82bc8ef99916b66
3
+ metadata.gz: 54f7ce2f282a5da9818948a40ec390c7c5cb13f0
4
+ data.tar.gz: 83fa2415988d4c7ec93098be26424cbd73dc5ee3
5
5
  SHA512:
6
- metadata.gz: a45aa55d9cde559f7a4f638d862ad6d1ec31c54c84570409cb5f566823a014c810ad100a14788431b7b02cc623dbed016ec1a91a97bfcf8a5b390ecf9b33cd87
7
- data.tar.gz: 3dd46dc13f6ec1bcece56b16079a1ca6eb2a2864f7ccf6feb30d8b6eb600f0abb899678495c6331094b9bb6c9a7d796eee440efbf5c8de1e2e154dd973158221
6
+ metadata.gz: 81fb4b71d9a0c17264dc11721df78b720d35e0fbdcc9c8ece31c223571d72e3f9c825fe96ef5c4c0ed8877b11d86bef9c0132c9557f963f5aa8a6b559b10b920
7
+ data.tar.gz: ec0db152836431cf3891de6802fda44b0dc4816f352fae76a897059f15badf7bc98f1f468e5b44942846c0489a8e3816dbcfdeed506abe5af71b3d83605b1df9
@@ -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 = env
35
- @config = (self.class.instance_variable_get(:@config_class) || ServiceSkeleton::Config).new(env, self)
36
- @logger = @config.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
- shutdown
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
 
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: 0.0.0.2.g46c1e0e
4
+ version: 0.0.0.3.g1269800
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Palmer