flatware 2.2.1 → 2.3.2

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: e4e66ab27a1e76fc9ca919c9b9de35006f88317cb6b5bf6f1b136b1b7eabc368
4
+ data.tar.gz: d16310a202a40d0e1a4147d31e1c97c8cc590f5d1b009b2576cefb9e79e47735
5
5
  SHA512:
6
- metadata.gz: 48e11bc65e1e0423567b21175a313766aeb1949aa3f7f168e005c3657f9a189da5003aea4c8f50230969875dc6363fe5e8eacebb0c594d4fdea28c3775082791
7
- data.tar.gz: 1f6abcc7d6b8d1e29e8c588e27dd077b8af754fb7c3b057f648d595974591c5069f147fe6b3f43768655add6553a090b240312180773f58db5d0b23f74e76cdc
6
+ metadata.gz: 3e1b6e794216a3724966e1465990d89a6d8d33f2ef2d58248b7ccb35e16451ad3f675c9b4f630135b9d4fbc61a75e4be32b844ee8758f1e9975dc80ffd13b32a
7
+ data.tar.gz: 341abe2ae2e05e2105f3de801fb8e8bd044028bc75a21529d4f5b2d1aab20b943d0b4d860cfff432e1f234d91dbd662db23c664543e3dd2ad2b8b2b95d315738
data/README.md CHANGED
@@ -40,13 +40,13 @@ $ flatware rspec
40
40
 
41
41
  The rspec runner can balance worker loads, making your suite even faster.
42
42
 
43
- It forms balaced groups of spec files according to their last run times, if you've set `example_status_persistence_file_path` [in your RSpec config](https://relishapp.com/rspec/rspec-core/v/3-8/docs/command-line/only-failures).
43
+ It forms balanced groups of spec files according to their last run times, if you've set `example_status_persistence_file_path` [in your RSpec config](https://relishapp.com/rspec/rspec-core/v/3-8/docs/command-line/only-failures).
44
44
 
45
- For this to work the configuration option must be loaded before any specs are run. The `.rspec` file is one way to achive this:
45
+ For this to work the configuration option must be loaded before any specs are run. The `.rspec` file is one way to achieve this:
46
46
 
47
47
  --require spec_helper
48
48
 
49
- But beware, if you're using ActiveRecord in your suite you'll need to avoid doing things that cause it to establish a database connection in `spec_helper.rb`. If ActiveRecord connects before flatware forks off workers, each will die messily. All of this will just work if you're following [the recomended pattern of splitting your helpers into `spec_helper` and `rails_helper`](https://github.com/rspec/rspec-rails/blob/v3.8.2/lib/generators/rspec/install/templates/spec/rails_helper.rb). Another option is to use [the configurable hooks](
49
+ But beware, if you're using ActiveRecord in your suite you'll need to avoid doing things that cause it to establish a database connection in `spec_helper.rb`. If ActiveRecord connects before flatware forks off workers, each will die messily. All of this will just work if you're following [the recommended pattern of splitting your helpers into `spec_helper` and `rails_helper`](https://github.com/rspec/rspec-rails/blob/v3.8.2/lib/generators/rspec/install/templates/spec/rails_helper.rb). Another option is to use [the configurable hooks](
50
50
  #faster-startup-with-activerecord
51
51
  ).
52
52
 
data/lib/flatware/cli.rb CHANGED
@@ -17,7 +17,7 @@ module Flatware
17
17
  aliases: '-w',
18
18
  type: :numeric,
19
19
  default: processors,
20
- desc: 'Number of concurent processes to run'
20
+ desc: 'Number of concurrent processes to run'
21
21
  )
22
22
  end
23
23
 
@@ -90,6 +90,6 @@ if loaded_flatware_gem_count.zero?
90
90
  warn(
91
91
  format(<<~MESSAGE, gem_list: flatware_gems.join(' or ')))
92
92
  The flatware gem is a dependency of flatware runners for rspec and cucumber.
93
- Install %<gem_list>s for more usefull commands.
93
+ Install %<gem_list>s for more useful commands.
94
94
  MESSAGE
95
95
  end
@@ -0,0 +1,82 @@
1
+ module Flatware
2
+ module Sink
3
+ class Signal
4
+ Message = Struct.new(:message)
5
+
6
+ attr_reader :formatter
7
+
8
+ def initialize(formatter, &on_interrupt)
9
+ @formatter = formatter
10
+ Thread.main[:signals] = Queue.new
11
+
12
+ @on_interrupt = on_interrupt
13
+ end
14
+
15
+ def listen
16
+ Thread.new(&method(:handle_signals))
17
+
18
+ ::Signal.trap('INT') { signals << :int }
19
+ ::Signal.trap('CLD') do
20
+ signals << :cld if child_failed?
21
+ end
22
+
23
+ self
24
+ end
25
+
26
+ def self.listen(formatter, &block)
27
+ new(formatter, &block).listen
28
+ end
29
+
30
+ private
31
+
32
+ def child_status
33
+ _worker_pid, status = begin
34
+ Process.wait2(-1, Process::WNOHANG)
35
+ rescue Errno::ECHILD
36
+ []
37
+ end
38
+ status
39
+ end
40
+
41
+ def child_statuses
42
+ statuses = []
43
+ loop do
44
+ status = child_status
45
+ return statuses unless status
46
+
47
+ statuses << status
48
+ end
49
+ end
50
+
51
+ def child_failed?
52
+ child_statuses.any? { |status| !status.success? }
53
+ end
54
+
55
+ def handle_signals
56
+ signal_message(signals.pop) do
57
+ Process.waitall
58
+ @on_interrupt.call
59
+ end
60
+
61
+ abort
62
+ end
63
+
64
+ def signal_message(signal)
65
+ formatter.message(Message.new(format(<<~MESSAGE, { cld: 'A worker died', int: 'Interrupted' }.fetch(signal))))
66
+
67
+ %s!
68
+
69
+ Waiting for workers to finish their current jobs...
70
+ MESSAGE
71
+
72
+ yield
73
+
74
+ formatter.message(Message.new('done.'))
75
+ end
76
+
77
+ def signals
78
+ Thread.main[:signals]
79
+ end
80
+ end
81
+ end
82
+ 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
@@ -24,6 +25,7 @@ module Flatware
24
25
  @checkpoints = []
25
26
  @completed_jobs = []
26
27
  @formatter = formatter
28
+ @interrupted = false
27
29
  @jobs = group_jobs(jobs, worker_count).freeze
28
30
  @queue = @jobs.dup
29
31
  @sink = sink
@@ -31,16 +33,16 @@ module Flatware
31
33
  end
32
34
 
33
35
  def start
34
- trap_interrupt
36
+ Signal.listen(formatter, &method(:on_interrupt))
35
37
  formatter.jobs jobs
36
38
  DRb.start_service(sink, self, verbose: Flatware.verbose?)
37
39
  DRb.thread.join
38
- !failures?
40
+ !(failures? || interrupted?)
39
41
  end
40
42
 
41
43
  def ready(worker)
42
44
  job = queue.shift
43
- if job && !(remaining_work.empty? || interruped?)
45
+ if job && !(remaining_work.empty? || interrupted?)
44
46
  workers << worker
45
47
  job
46
48
  else
@@ -72,29 +74,13 @@ module Flatware
72
74
 
73
75
  private
74
76
 
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!'
77
+ def on_interrupt
78
+ @interrupted = true
88
79
  summarize_remaining
89
- puts "\n\nCleaning up. Please wait...\n"
90
- Process.waitall
91
- puts 'done.'
92
- abort
93
80
  end
94
81
 
95
- def interruped?
96
- signals = Thread.main[:signals]
97
- signals && !signals.empty?
82
+ def interrupted?
83
+ @interrupted
98
84
  end
99
85
 
100
86
  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.2'
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.2
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-05-17 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