flatware 2.2.0 → 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: cf9e819cd4142e9648a8dbe098afc8077e5a6dc64e58dc1fe1a025efc081a105
4
- data.tar.gz: 947a36ace6700bb8280af4626d80199b186120e6a835802e064d13cfbe16fba0
3
+ metadata.gz: f3dfa03a78403cf9d0b10b97ac354baba9353a6847bcbbc9b150b7deaa8a4f68
4
+ data.tar.gz: e2181f1f91b2b313ab42d39c93ce209efc432b29192737f7b9d5e06d13f637ce
5
5
  SHA512:
6
- metadata.gz: abfe9079d1576452f489eb16300934838d7efef290523af3369918f1e99efc30608f8faa93f20f096710551d03fb892647ee2891e0767a300086345abf3e022b
7
- data.tar.gz: 55f1933b44ebc6783598acb067ca7c33a42a2d7bbbf49310aa46dadefcfdf9e215b66aa08e2948792660aacb84c0a0fd9c3a509c2d84e0627522cff8d334977f
6
+ metadata.gz: 63b9c6f997e89382276b56797cf0e0b53155c30e11a5e22157c03a93da7cd616bffde249283a6ed7a29affc1b9da5baa211c2963e98402998068c7a9f856ed33
7
+ data.tar.gz: dba4525f41243955e2f0f3db5a8685031a38eb66192de319c110eae41450fcd55ad995d56c3025e01cb8ad61a50dce04dec4dcc1e45ed54f36dfe011554f5339
data/README.md CHANGED
@@ -106,6 +106,11 @@ Flatware has a couple lifecycle callbacks that you can use to avoid booting your
106
106
  over again on every core. One way to take advantage of this via a `spec/flatware_helper.rb` file like so:
107
107
 
108
108
  ```ruby
109
+ ##
110
+ # uncomment if you get a segmentation fault from the "pg" gem
111
+ # @see https://github.com/ged/ruby-pg/issues/311#issuecomment-1609970533
112
+ # ENV["PGGSSENCMODE"] = "disable"
113
+
109
114
  Flatware.configure do |conf|
110
115
  conf.before_fork do
111
116
  require 'rails_helper'
@@ -114,6 +119,11 @@ Flatware.configure do |conf|
114
119
  end
115
120
 
116
121
  conf.after_fork do |test_env_number|
122
+ ##
123
+ # uncomment if you're using SimpleCov and have started it in `rails_helper` as suggested here:
124
+ # @see https://github.com/simplecov-ruby/simplecov/tree/main?tab=readme-ov-file#use-it-with-any-framework
125
+ # SimpleCov.at_fork.call(test_env_number)
126
+
117
127
  config = ActiveRecord::Base.connection_db_config.configuration_hash
118
128
 
119
129
  ActiveRecord::Base.establish_connection(
@@ -126,6 +136,15 @@ end
126
136
  ```
127
137
  Now when I run `bundle exec flatware rspec -r ./spec/flatware_helper` My app only boots once, rather than once per core.
128
138
 
139
+ ## SimpleCov
140
+
141
+ If you're using SimpleCov, follow [their directions](https://github.com/simplecov-ruby/simplecov/tree/main?tab=readme-ov-file#use-it-with-any-framework) to install. When you have it working as desired for serial runs, add
142
+ `SimpleCov.at_fork.call(test_env_number)` to flatware's `after_fork` hook. You should now get the same coverage stats from parallel and serial runs.
143
+
144
+ ## Segmentation faults in the PG gem
145
+
146
+ If you get a segmentation fault on start you may need to add `ENV["PGGSSENCMODE"] = "disable"` to the top of your flatware helper.
147
+
129
148
  ## Design Goals
130
149
 
131
150
  ### Maintainable
@@ -170,3 +189,10 @@ Do whatever you want. I'd love to help make sure Flatware meets your needs.
170
189
  [![Hashrocket logo](https://hashrocket.com/hashrocket_logo.svg)](https://hashrocket.com)
171
190
 
172
191
  Flatware is supported by the team at [Hashrocket](https://hashrocket.com), a multidisciplinary design & development consultancy. If you'd like to [work with us](https://hashrocket.com/contact-us/hire-us) or [join our team](https://hashrocket.com/contact-us/jobs), don't hesitate to get in touch.
192
+
193
+
194
+ # TODO:
195
+
196
+ possible simplecov fixes
197
+
198
+ 1. seems like we won't get the same results as serial rspec runs unless we start simplecov after fork. And if we do that, I think a process needs to claim to be the last one for simplecov to run the merge.
data/lib/flatware/cli.rb CHANGED
@@ -55,7 +55,8 @@ module Flatware
55
55
 
56
56
  def start_sink(jobs:, workers:, formatter:)
57
57
  $0 = 'flatware sink'
58
- Process.setpgrp
58
+ try_setpgrp
59
+
59
60
  passed = Sink.start_server(
60
61
  jobs: jobs,
61
62
  formatter: Flatware::Broadcaster.new([formatter]),
@@ -65,6 +66,12 @@ module Flatware
65
66
  exit passed ? 0 : 1
66
67
  end
67
68
 
69
+ def try_setpgrp
70
+ Process.setpgrp
71
+ rescue Errno::EPERM => e
72
+ Flatware.log 'continuing after: Process.setpgrp:', e.message
73
+ end
74
+
68
75
  def workers
69
76
  options[:workers]
70
77
  end
@@ -3,11 +3,11 @@ module Flatware
3
3
  attr_reader :class, :message, :cause
4
4
  attr_accessor :backtrace
5
5
 
6
- def initialize(klass, message, backtrace, cause = '')
6
+ def initialize(klass, message, backtrace, cause = nil)
7
7
  @class = serialized(klass)
8
8
  @message = message
9
9
  @backtrace = backtrace
10
- @cause = cause
10
+ @cause = cause && SerializedException.from(cause)
11
11
  end
12
12
 
13
13
  def self.from(exception)
@@ -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.0'
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.0
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-02-14 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