service_skeleton 0.0.0.16.g99ff4d7 → 0.0.0.20.gb9a0460

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9fe5415554536e557f6666ea6fde587d417a3f98878194949f48037c13b876e1
4
- data.tar.gz: 9606acf330ed46324bbe1f39066844463e82f34ee2ec6b979ccd04fc54dcd8c7
3
+ metadata.gz: 651f874d0096f67e63ff46f957125c53b032861d34b6b43cfdfb2113eca7ad65
4
+ data.tar.gz: 78c72f06cb3693d10d9c02338191eb0fef4a8171a97a138c01c42374133ecef6
5
5
  SHA512:
6
- metadata.gz: 72494f036549c13931e2d8ad6d3928e2bf8db14b10da2e9007ce3d10ebb8d54d84c316cc3fbbde4de26e234ecc5fbb0a894d73ebab54cabbd28626b3f43e1333
7
- data.tar.gz: acde5210642f771083ffa5406066b53c8ff5eddc06281567fd45cb45a4b0b85c2add07101c5ed5727ee7959563b07538ad97e8fac1f2db27791e2dd3a0a6b1df
6
+ metadata.gz: 59635704ca571789796e46449916154cbcc4194e39a6bf754c564490e7acd4a3217e32693090920b8c5195672f6d602426e85b80f52fec5bc9d6f4d3dd2c6f35
7
+ data.tar.gz: b67dd4d48fe6c468f10b7e34deb54195eee9f55e460f8179714228f727e5ff941f1200347825e8108fdb17ccd97da0b00d53431adb887b7ac37ee941ad3bd55d
data/.editorconfig ADDED
@@ -0,0 +1,7 @@
1
+ [*.rb]
2
+ indent_style = space
3
+ indent_size = 2
4
+ end_of_line = lf
5
+ insert_final_newline = true
6
+ charset = utf-8
7
+ trim_trailing_whitespace = true
@@ -54,15 +54,24 @@ class ServiceSkeleton
54
54
  end
55
55
  end
56
56
 
57
- def stop!
57
+ def stop!(force = nil)
58
58
  @bg_worker_op_mutex.synchronize do
59
59
  return if @bg_worker_thread.nil?
60
60
 
61
- logger.debug("BackgroundWorker(#{self.class})#stop!") { "Terminating worker thread #{Thread.current.object_id} as requested" }
61
+ logger.debug("BackgroundWorker(#{self.class})#stop!") { "Terminating worker thread #{@bg_worker_thread.object_id} as requested" }
62
62
 
63
- shutdown
63
+ if force == :force
64
+ @bg_worker_thread.raise(TerminateBackgroundThread)
65
+ else
66
+ shutdown
67
+ end
68
+
69
+ begin
70
+ @bg_worker_thread.join unless @bg_worker_thread == Thread.current
71
+ rescue TerminateBackgroundThread
72
+ nil
73
+ end
64
74
 
65
- @bg_worker_thread.join
66
75
  @bg_worker_thread = nil
67
76
 
68
77
  logger.debug("BackgroundWorker(#{self.class})#stop!") { "Worker thread terminated" }
@@ -42,6 +42,8 @@ class ServiceSkeleton
42
42
 
43
43
  @signal_registry = []
44
44
 
45
+ @handler_install_mutex = Mutex.new
46
+
45
47
  super
46
48
  end
47
49
 
@@ -62,16 +64,18 @@ class ServiceSkeleton
62
64
  # specifier by `Signal.trap`.
63
65
  #
64
66
  def hook_signal(sig, &blk)
65
- @bg_worker_op_mutex.synchronize do
66
- handler_num = @signal_registry.length
67
+ logger.debug(logloc) { "Hooking signal #{sig}" }
67
68
 
68
- if handler_num > 255
69
- raise RuntimeError,
70
- "Signal hook limit reached. Slow down there, pardner"
71
- end
69
+ handler_num = @signal_registry.length
72
70
 
73
- sigspec = { signal: sig, callback: blk }
71
+ if handler_num > 255
72
+ raise RuntimeError,
73
+ "Signal hook limit reached. Slow down there, pardner"
74
+ end
74
75
 
76
+ sigspec = { signal: sig, callback: blk }
77
+
78
+ @handler_install_mutex.synchronize do
75
79
  if @bg_worker_thread
76
80
  install_handler(sigspec, handler_num)
77
81
  else
@@ -84,11 +88,13 @@ class ServiceSkeleton
84
88
  end
85
89
 
86
90
  def start
87
- logger.info(logloc) { "Starting signal handler with #{@signal_registry.length} hooks" }
91
+ @handler_install_mutex.synchronize do
92
+ logger.info(logloc) { "Starting signal handler with #{@signal_registry.length} hooks" }
88
93
 
89
- @r, @w = IO.pipe
94
+ @r, @w = IO.pipe
90
95
 
91
- install_signal_handlers
96
+ install_signal_handlers
97
+ end
92
98
 
93
99
  loop do
94
100
  begin
@@ -99,6 +105,7 @@ class ServiceSkeleton
99
105
  break
100
106
  else
101
107
  c = ios.first.first.read_nonblock(1)
108
+ logger.debug(logloc) { "Received character #{c.inspect} from signal pipe" }
102
109
  handle_signal(c)
103
110
  end
104
111
  else
@@ -146,6 +153,7 @@ class ServiceSkeleton
146
153
  end
147
154
 
148
155
  def install_handler(sigspec, i)
156
+ logger.debug(logloc) { "Installing signal handler for #{sigspec[:signal]}" }
149
157
  chain = nil
150
158
 
151
159
  p = ->(*args) do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: service_skeleton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.16.g99ff4d7
4
+ version: 0.0.0.20.gb9a0460
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Palmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-27 00:00:00.000000000 Z
11
+ date: 2019-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: frankenstein
@@ -261,6 +261,7 @@ executables: []
261
261
  extensions: []
262
262
  extra_rdoc_files: []
263
263
  files:
264
+ - ".editorconfig"
264
265
  - ".gitignore"
265
266
  - ".rubocop.yml"
266
267
  - ".travis.yml"