switchman 3.3.0 → 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: 0730763611a9f47cf3b9a39d5e3a9969189067772c743bad82729c670d18e545
4
- data.tar.gz: 4136ab04f9eac6c48ae4ad7a70b284845f095e3fc4153a8d5a5023f2bc5e312d
3
+ metadata.gz: eba3197eb56e020790a7ff144dc55f15bb9ad84f523728e70d7573aa5a778f2d
4
+ data.tar.gz: e8003ce68cf4ae8262f6d40c8229c44ceb785c8313e717fca2b00edadb8e61e9
5
5
  SHA512:
6
- metadata.gz: ad391b862e5428999a5260278e767dae4a1266eb99fd2bab18619b26302542d67d50fee3277ff27711ce4eaec68fbf5428773d17b03b7d235e501baeb06a1623
7
- data.tar.gz: 87cee001748bcea7ce0f46a4d673a2c7ac3aefb16b99f84d463fbaff3804a98cd53184dd271a3b19261f89baef91151d85728076b76484646d5be95af1f101cb
6
+ metadata.gz: dd810811744c3ebe8f6dcef36c00a0c04dbaaca70aaa574a33bd9496e204c3afcd0696088fa79e500eb28cc835738d3f273bebe9fc023c86794353348e41e6be
7
+ data.tar.gz: f7c6804dbb5abba70034eeae11b9cf2f77e42052fb23366a68d4b139eddfd9434ee6190f9d391112e82017187473bdc11ded1a62a474a02e113ff15d7d399a5a
@@ -58,9 +58,10 @@ module Switchman
58
58
  end
59
59
 
60
60
  %I[update_all delete_all].each do |method|
61
+ arg_params = RUBY_VERSION <= '2.8' ? '*args' : '*args, **kwargs'
61
62
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
62
- def #{method}(*args)
63
- result = self.activate(unordered: true) { |relation| relation.call_super(#{method.inspect}, Relation, *args) }
63
+ def #{method}(#{arg_params})
64
+ result = self.activate(unordered: true) { |relation| relation.call_super(#{method.inspect}, Relation, #{arg_params}) }
64
65
  result = result.sum if result.is_a?(Array)
65
66
  result
66
67
  end
@@ -12,8 +12,14 @@ module Switchman
12
12
  method.super_method
13
13
  end
14
14
 
15
- def call_super(method, above_module, *args, &block)
16
- super_method_above(method, above_module).call(*args, &block)
15
+ if RUBY_VERSION <= '2.8'
16
+ def call_super(method, above_module, *args, &block)
17
+ super_method_above(method, above_module).call(*args, &block)
18
+ end
19
+ else
20
+ def call_super(method, above_module, *args, **kwargs, &block)
21
+ super_method_above(method, above_module).call(*args, **kwargs, &block)
22
+ end
17
23
  end
18
24
  end
19
25
  end
@@ -13,8 +13,9 @@ module Switchman
13
13
  end
14
14
 
15
15
  %w[update_all delete_all].each do |method|
16
+ arg_params = RUBY_VERSION <= '2.8' ? '*args' : '*args, **kwargs'
16
17
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
17
- def #{method}(*args)
18
+ def #{method}(#{arg_params})
18
19
  db = Shard.current(connection_class_for_self).database_server
19
20
  db.unguard { super }
20
21
  end
@@ -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.0'
4
+ VERSION = '3.3.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switchman
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-12-08 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