riser 0.1.8 → 0.1.9

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: b9ae7fbe0d87eb7546bcd3df41adb101c0c66bb964e07de7d3658cf63d397562
4
- data.tar.gz: 288ab38bbd42a41f31a399f12289adf4cdc8ad700ac649a09fea2ec593a2b4f3
3
+ metadata.gz: 0c9d1d7238c0a2002a16d53c594c40a8f63f8cd29548bd376b59acf280305960
4
+ data.tar.gz: 3db48c1fffc46fa46af97b479a10737c65c7dcc27690dd7eca85e66897bdd86d
5
5
  SHA512:
6
- metadata.gz: 98f72efdfda6c5eee8e7adcb0b3a0d5d6ceca0df6f73b1bd544b3eae535f62e671b76a29074bd60c9992943852e89d294e02b38788496e97bf0f66c276462dd4
7
- data.tar.gz: e8f52a3f99f42d6bb4e7c05a260165a82d4712669490f9717c95e87639af9551c3aa0288102a813a212897d0f6f8b83465255d0eebdda89f69ead6d7e7757795
6
+ metadata.gz: 7dfeae8c5c37eff1716fee819db62b642d2da12ee692c564e5813085fe8f98b87ad65fed3b041df7e573c43de2154b2cadc9401259d0739ee56c05a6a1ea3780
7
+ data.tar.gz: e0aeff5527e15469ea7eecfa84d5848a3ad2716a5e30a58b1153790e822e1c5f096d69826aee7c725ecf94221801ca61be989bc9c0c1b39b30ea62e79392b6e2
@@ -218,6 +218,7 @@ module Riser
218
218
  @accept = nil
219
219
  @accept_return = nil
220
220
  @dispatch = nil
221
+ @dispose = nil
221
222
  @stop_state = nil
222
223
  @stat_operation_queue = []
223
224
  end
@@ -271,6 +272,11 @@ module Riser
271
272
  nil
272
273
  end
273
274
 
275
+ def dispose(&block) # :yields:
276
+ @dispose = block
277
+ nil
278
+ end
279
+
274
280
  # should be called from signal(2) handler
275
281
  def signal_stop_graceful
276
282
  @stop_state ||= :graceful
@@ -279,7 +285,9 @@ module Riser
279
285
 
280
286
  # should be called from signal(2) handler
281
287
  def signal_stop_forced
282
- @stop_state ||= :forced
288
+ if (! @stop_state || @stop_state == :graceful) then
289
+ @stop_state = :forced
290
+ end
283
291
  nil
284
292
  end
285
293
 
@@ -339,12 +347,16 @@ module Riser
339
347
  thread_list << Thread.start(i) {|thread_number|
340
348
  begin
341
349
  Thread.current[:number] = thread_number
342
- while (socket = queue.pop)
343
- begin
344
- @dispatch.call(socket)
345
- ensure
346
- socket.close unless socket.closed?
350
+ begin
351
+ while (socket = queue.pop)
352
+ begin
353
+ @dispatch.call(socket)
354
+ ensure
355
+ socket.close unless socket.closed?
356
+ end
347
357
  end
358
+ ensure
359
+ @dispose.call
348
360
  end
349
361
  rescue
350
362
  error_lock.synchronize{
@@ -379,19 +391,31 @@ module Riser
379
391
  queue.close
380
392
  end
381
393
 
382
- @at_stop.call(@stop_state)
383
- case (@stop_state)
384
- when :graceful
385
- for thread in thread_list
386
- thread.join
387
- end
388
- when :forced
389
- for thread in thread_list
390
- thread.kill
391
- end
392
- else
393
- raise "internal error: unknown stop state <#{@stop_state.inspect}>"
394
- end
394
+ begin
395
+ done = catch(:retry_stopping) {
396
+ @at_stop.call(@stop_state)
397
+ case (@stop_state)
398
+ when :graceful
399
+ until (thread_list.empty?)
400
+ until (thread_list[0].join(@thread_queue_polling_timeout_seconds))
401
+ if (@stop_state == :forced) then
402
+ throw(:retry_stopping)
403
+ end
404
+ end
405
+ thread_list.shift
406
+ end
407
+ when :forced
408
+ until (thread_list.empty?)
409
+ thread_list[0].kill
410
+ thread_list.shift
411
+ end
412
+ else
413
+ raise "internal error: unknown stop state <#{@stop_state.inspect}>"
414
+ end
415
+
416
+ true
417
+ }
418
+ end until (done)
395
419
  ensure
396
420
  @postprocess.call
397
421
  end
@@ -553,6 +577,7 @@ module Riser
553
577
  }
554
578
  thread_dispatcher.accept_return{ child_io.write(RADY_CMD) }
555
579
  thread_dispatcher.dispatch(&@dispatch)
580
+ thread_dispatcher.dispose(&NO_CALL)
556
581
 
557
582
  Signal.trap(SIGNAL_STOP_GRACEFUL) { thread_dispatcher.signal_stop_graceful }
558
583
  Signal.trap(SIGNAL_STOP_FORCED) { thread_dispatcher.signal_stop_forced }
@@ -627,12 +652,12 @@ module Riser
627
652
  response = process.io.read(RADY_LEN)
628
653
  response == RADY_CMD or raise "internal error: unknown response <#{response.inspect}>"
629
654
  }
630
- @process_dispatcher.start
631
-
632
- for process in process_list
655
+ @process_dispatcher.dispose{
656
+ process = process_list[Thread.current[:number]]
633
657
  Process.wait(process.pid)
634
658
  process.io.close
635
- end
659
+ }
660
+ @process_dispatcher.start
636
661
 
637
662
  nil
638
663
  end
@@ -772,6 +797,7 @@ module Riser
772
797
  }
773
798
  @dispatcher.accept_return(&NO_CALL)
774
799
  @dispatcher.dispatch(&@dispatch)
800
+ @dispatcher.dispose(&NO_CALL)
775
801
  end
776
802
 
777
803
  nil
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Riser
4
- VERSION = '0.1.8'.freeze
4
+ VERSION = '0.1.9'.freeze
5
5
  end
6
6
 
7
7
  # Local Variables:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - TOKI Yoshinori
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-14 00:00:00.000000000 Z
11
+ date: 2019-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler