switchman 3.3.1 → 3.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0330d210ee4f44c8ceb3b66ba1536f5538c4a1efcd4a939d492ffa65602fca7
4
- data.tar.gz: '0787f10b30acc34e0a5e48423c524d2db27b8b92dabd76bf567fb6631c0587c3'
3
+ metadata.gz: eba3197eb56e020790a7ff144dc55f15bb9ad84f523728e70d7573aa5a778f2d
4
+ data.tar.gz: e8003ce68cf4ae8262f6d40c8229c44ceb785c8313e717fca2b00edadb8e61e9
5
5
  SHA512:
6
- metadata.gz: 65e0cbb8c9015940209145aa229648fa763d999399053e9046b0b4a60e1aae1ebfe419983776364e7e2460ca2e0cc0021188d286a8da6a9d9c0a74bd59d1bbc2
7
- data.tar.gz: db938a240af2ffb146453536d42db25d38ac13ca136b757d219fef46cf99476c0916beb65c8e06e2bc48067b94736d8f88b4c13519f85d99ec2b07fc423eccc9
6
+ metadata.gz: dd810811744c3ebe8f6dcef36c00a0c04dbaaca70aaa574a33bd9496e204c3afcd0696088fa79e500eb28cc835738d3f273bebe9fc023c86794353348e41e6be
7
+ data.tar.gz: f7c6804dbb5abba70034eeae11b9cf2f77e42052fb23366a68d4b139eddfd9434ee6190f9d391112e82017187473bdc11ded1a62a474a02e113ff15d7d399a5a
@@ -120,7 +120,8 @@ module Switchman
120
120
  # forking.
121
121
  # exception: - :ignore, :raise, :defer (wait until the end and raise the first
122
122
  # error), or a proc
123
- def with_each_shard(*args, parallel: false, exception: :raise, &block)
123
+ # output: - :simple, :decorated (with database_server_id:shard_name)
124
+ def with_each_shard(*args, parallel: false, exception: :raise, output: :simple)
124
125
  raise ArgumentError, "wrong number of arguments (#{args.length} for 0...2)" if args.length > 2
125
126
 
126
127
  return Array.wrap(yield) unless default.is_a?(Shard)
@@ -164,20 +165,21 @@ module Switchman
164
165
  parent_process_name = `ps -ocommand= -p#{Process.pid}`.slice(/#{$0}.*/)
165
166
  ret = ::Parallel.map(scopes, in_processes: scopes.length > 1 ? parallel : 0) do |server, subscope|
166
167
  name = server.id
167
- # rubocop:disable Style/GlobalStdStream
168
- $stdout = Parallel::PrefixingIO.new(name, STDOUT)
169
- $stderr = Parallel::PrefixingIO.new(name, STDERR)
170
- # rubocop:enable Style/GlobalStdStream
168
+ last_description = name
169
+
171
170
  begin
172
171
  max_length = 128 - name.length - 3
173
172
  short_parent_name = parent_process_name[0..max_length] if max_length >= 0
174
173
  new_title = [short_parent_name, name].join(' ')
175
174
  Process.setproctitle(new_title)
176
175
  Switchman.config[:on_fork_proc]&.call
177
- with_each_shard(subscope, classes, exception: exception, &block).map { |result| Parallel::ResultWrapper.new(result) }
176
+ with_each_shard(subscope, classes, exception: exception, output: :decorated) do
177
+ last_description = Shard.current.description
178
+ Parallel::ResultWrapper.new(yield)
179
+ end
178
180
  rescue => e
179
181
  logger.error e.full_message
180
- Parallel::QuietExceptionWrapper.new(name, ::Parallel::ExceptionWrapper.new(e))
182
+ Parallel::QuietExceptionWrapper.new(last_description, ::Parallel::ExceptionWrapper.new(e))
181
183
  end
182
184
  end.flatten
183
185
 
@@ -195,14 +197,20 @@ module Switchman
195
197
 
196
198
  classes ||= []
197
199
 
198
- previous_shard = nil
199
200
  result = []
200
201
  ex = nil
202
+ old_stdout = $stdout
203
+ old_stderr = $stderr
201
204
  scope.each do |shard|
202
205
  # shard references a database server that isn't configured in this environment
203
206
  next unless shard.database_server
204
207
 
205
208
  shard.activate(*classes) do
209
+ if output == :decorated
210
+ $stdout = Parallel::PrefixingIO.new(shard.description, $stdout)
211
+ $stderr = Parallel::PrefixingIO.new(shard.description, $stderr)
212
+ end
213
+
206
214
  result.concat Array.wrap(yield)
207
215
  rescue
208
216
  case exception
@@ -216,8 +224,10 @@ module Switchman
216
224
  else
217
225
  raise
218
226
  end
227
+ ensure
228
+ $stdout = old_stdout
229
+ $stderr = old_stderr
219
230
  end
220
- previous_shard = shard
221
231
  end
222
232
  raise ex if ex
223
233
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Switchman
4
- VERSION = '3.3.1'
4
+ VERSION = '3.3.2'
5
5
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switchman
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.1
4
+ version: 3.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
8
8
  - James Williams
9
9
  - Jacob Fugal
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-12-20 00:00:00.000000000 Z
13
+ date: 2023-02-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -300,7 +300,7 @@ licenses:
300
300
  - MIT
301
301
  metadata:
302
302
  rubygems_mfa_required: 'true'
303
- post_install_message:
303
+ post_install_message:
304
304
  rdoc_options: []
305
305
  require_paths:
306
306
  - lib
@@ -315,8 +315,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
315
315
  - !ruby/object:Gem::Version
316
316
  version: '0'
317
317
  requirements: []
318
- rubygems_version: 3.3.7
319
- signing_key:
318
+ rubygems_version: 3.1.6
319
+ signing_key:
320
320
  specification_version: 4
321
321
  summary: Rails sharding magic
322
322
  test_files: []