oni 4.2.2 → 4.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/oni/daemon.rb +30 -18
  3. data/lib/oni/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d23d90e32e433203a63413d211532265e4ff02e550298d324521f77cc3295ef7
4
- data.tar.gz: 04f1e134b4d31efd0d79191ba37c9c8d63a33ea056edffc4cfbafffaa0268375
3
+ metadata.gz: 40eeae757bf8695a6f2ed1256ad7bdb670eb4e303f84519f55fcfa4958b8e948
4
+ data.tar.gz: 1152004d002543f7a5e838e6da6eba80cc92469b84b24916217071f42c40d0e4
5
5
  SHA512:
6
- metadata.gz: 7b50421bc3a740682a3d0889c8dcf0ddc616bdf1dac8b1e32d9aeef7c4469c156785bd995d071b5457750f0b9b98f4b27b927b043113b45c1f998816865a782a
7
- data.tar.gz: 9076cf44c34dd26a2377631fb42daae148b7d0507970a1ec8b7921052f101dcc4b8119c4c474a6f2bb2c16cf8962ff2d1b08cf0ced05b8bfbfe35bb76f6a57ef
6
+ metadata.gz: d242b9d34545a45d799a8fc244ea20060e76dc0dacaf972041a537ff8e3747ebeffd0be9df82ef894ece79e99f2a4bb9c2315314097d0d0310e0318ab51dc2df
7
+ data.tar.gz: 108854de0df628b2623b96f4cc4e6696f6eb4b14e0302e56d6e1ba237145cc788636d240171e3a0c85e21a9d9195502bc34fcf04fb44fe55784c378a9daac3ad
data/lib/oni/daemon.rb CHANGED
@@ -41,7 +41,7 @@ module Oni
41
41
  # is defined.
42
42
  #
43
43
  def initialize
44
- @daemon_workers = {}
44
+ @daemon_workers = Hash.new{ |h, k| h[k] = [] }
45
45
 
46
46
  after_initialize if respond_to?(:after_initialize)
47
47
  end
@@ -56,16 +56,15 @@ module Oni
56
56
  def start
57
57
  before_start if respond_to? :before_start
58
58
 
59
- return run_thread if threads <= 1
60
- return spawn_worker if workers <= 1
61
-
62
- Array.new workers do |i|
63
- Thread.new do
64
- Process.wait fork{ spawn_worker i+1 } while true
65
- end
66
- end.each(&:join)
59
+ wthreads = if threads <= 1 then [run_thread]
60
+ elsif workers <= 1 then standard_worker
61
+ else wthreads = Array.new(workers){ |i| spawn_worker i } end
67
62
 
68
63
  after_start if respond_to? :after_start
64
+
65
+ %i[INT TERM].each{ |sig| trap(sig){ stop } }
66
+ wthreads.each(&:join) if workers > 1
67
+
69
68
  rescue => error
70
69
  error(error)
71
70
  end
@@ -80,6 +79,7 @@ module Oni
80
79
  worker_threads.each(&:kill)
81
80
  worker_threads.clear
82
81
  end
82
+ exit
83
83
  end
84
84
 
85
85
  def workers
@@ -185,11 +185,25 @@ module Oni
185
185
  #
186
186
  # @return [Thread]
187
187
  #
188
- def spawn_worker i = nil
189
- Process.setproctitle "#{$0}: worker #{i}" if i
188
+ def spawn_worker name = nil, &block
189
+ Thread.new do
190
+ pid = nil
191
+ loop do # keep restarting for OOM and other cases
192
+ pid = fork do
193
+ Process.setproctitle "#{$0}: worker #{name}" if name
194
+
195
+ if block then yield else standard_worker end
196
+ end
197
+ Process.wait pid
198
+ end
199
+ ensure
200
+ Process.kill :KILL, pid
201
+ end
202
+ end
190
203
 
191
- daemon_workers[Process.pid] = Array.new threads do
192
- spawn_thread
204
+ def standard_worker
205
+ Array.new(threads) do
206
+ spawn_thread.tap{ |t| daemon_workers[Process.pid] << t }
193
207
  end.each(&:join)
194
208
  end
195
209
 
@@ -199,11 +213,9 @@ module Oni
199
213
  # @return [Thread]
200
214
  #
201
215
  def spawn_thread
202
- thread = Thread.new { run_thread }
203
-
204
- thread.abort_on_exception = true
205
-
206
- return thread
216
+ Thread.new{ run_thread }.tap do |t|
217
+ t.abort_on_exception = true
218
+ end
207
219
  end
208
220
 
209
221
  ##
data/lib/oni/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Oni
2
- VERSION = '4.2.2'
2
+ VERSION = '4.3.1'
3
3
  end # Oni
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oni
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.2
4
+ version: 4.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yorick Peterse
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-06-01 00:00:00.000000000 Z
12
+ date: 2022-06-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake