flatware 2.2.1 → 2.3.1

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: 278612d774eb619a0548544e33650c8f73b4fa1b88de900027aba730a46c51bd
4
- data.tar.gz: a1ac3e33ff822f2cac88fe24914d1034bffd40872ca0e10791e8019a60f64d68
3
+ metadata.gz: f3dfa03a78403cf9d0b10b97ac354baba9353a6847bcbbc9b150b7deaa8a4f68
4
+ data.tar.gz: e2181f1f91b2b313ab42d39c93ce209efc432b29192737f7b9d5e06d13f637ce
5
5
  SHA512:
6
- metadata.gz: 48e11bc65e1e0423567b21175a313766aeb1949aa3f7f168e005c3657f9a189da5003aea4c8f50230969875dc6363fe5e8eacebb0c594d4fdea28c3775082791
7
- data.tar.gz: 1f6abcc7d6b8d1e29e8c588e27dd077b8af754fb7c3b057f648d595974591c5069f147fe6b3f43768655add6553a090b240312180773f58db5d0b23f74e76cdc
6
+ metadata.gz: 63b9c6f997e89382276b56797cf0e0b53155c30e11a5e22157c03a93da7cd616bffde249283a6ed7a29affc1b9da5baa211c2963e98402998068c7a9f856ed33
7
+ data.tar.gz: dba4525f41243955e2f0f3db5a8685031a38eb66192de319c110eae41450fcd55ad995d56c3025e01cb8ad61a50dce04dec4dcc1e45ed54f36dfe011554f5339
@@ -0,0 +1,51 @@
1
+ module Flatware
2
+ module Sink
3
+ class Signal
4
+ def initialize(&on_interrupt)
5
+ Thread.main[:signals] = Queue.new
6
+
7
+ @on_interrupt = on_interrupt
8
+ end
9
+
10
+ def interruped?
11
+ !signals.empty?
12
+ end
13
+
14
+ def listen
15
+ Thread.new(&method(:handle_signals))
16
+
17
+ ::Signal.trap('INT') { signals << :int }
18
+ ::Signal.trap('CLD') { signals << :cld }
19
+
20
+ self
21
+ end
22
+
23
+ def self.listen(&block)
24
+ new(&block).listen
25
+ end
26
+
27
+ private
28
+
29
+ def handle_signals
30
+ puts signal_message(signals.pop)
31
+ Process.waitall
32
+ @on_interrupt.call
33
+ puts 'done.'
34
+ abort
35
+ end
36
+
37
+ def signal_message(signal)
38
+ format(<<~MESSAGE, { cld: 'A worker died', int: 'Interrupted' }.fetch(signal))
39
+
40
+ %s!
41
+
42
+ Cleaning up. Please wait...
43
+ MESSAGE
44
+ end
45
+
46
+ def signals
47
+ Thread.main[:signals]
48
+ end
49
+ end
50
+ end
51
+ end
data/lib/flatware/sink.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'drb/drb'
2
2
  require 'set'
3
+ require 'flatware/sink/signal'
3
4
 
4
5
  module Flatware
5
6
  module Sink
@@ -31,7 +32,7 @@ module Flatware
31
32
  end
32
33
 
33
34
  def start
34
- trap_interrupt
35
+ @signal = Signal.listen(&method(:summarize_remaining))
35
36
  formatter.jobs jobs
36
37
  DRb.start_service(sink, self, verbose: Flatware.verbose?)
37
38
  DRb.thread.join
@@ -72,29 +73,8 @@ module Flatware
72
73
 
73
74
  private
74
75
 
75
- def trap_interrupt
76
- Thread.main[:signals] = Queue.new
77
-
78
- Thread.new(&method(:handle_interrupt))
79
-
80
- trap 'INT' do
81
- Thread.main[:signals] << :int
82
- end
83
- end
84
-
85
- def handle_interrupt
86
- Thread.main[:signals].pop
87
- puts 'Interrupted!'
88
- summarize_remaining
89
- puts "\n\nCleaning up. Please wait...\n"
90
- Process.waitall
91
- puts 'done.'
92
- abort
93
- end
94
-
95
76
  def interruped?
96
- signals = Thread.main[:signals]
97
- signals && !signals.empty?
77
+ @signal&.interruped?
98
78
  end
99
79
 
100
80
  def check_finished!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flatware
4
- VERSION = '2.2.1'
4
+ VERSION = '2.3.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flatware
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Dunn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-02 00:00:00.000000000 Z
11
+ date: 2024-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -45,6 +45,7 @@ files:
45
45
  - lib/flatware/serialized_exception.rb
46
46
  - lib/flatware/sink.rb
47
47
  - lib/flatware/sink/client.rb
48
+ - lib/flatware/sink/signal.rb
48
49
  - lib/flatware/version.rb
49
50
  - lib/flatware/worker.rb
50
51
  homepage: http://github.com/briandunn/flatware