solr_wrapper 1.0.0 → 1.1.0

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
  SHA1:
3
- metadata.gz: '092270d968ea024833bc6185caf854c05c8e623e'
4
- data.tar.gz: 83d3dd71ca0de7c18ee9090a06ff051b174dbf4a
3
+ metadata.gz: cad9f5f469895a40d84f56ad3616e31c57e70d71
4
+ data.tar.gz: d58ab53dbd4f74094c54236d17b77b94603bc700
5
5
  SHA512:
6
- metadata.gz: c4da5d83939b7d10b089d4453b79fb778aa499809cbd114d634fe8e7e790a21896c73320055fa43d3682559768fcb5729f2062bde7ab1ee9beeb92e967c1cf50
7
- data.tar.gz: c7373e52dcd5520e541947655b1e95c6fcd53e9ccf7b356d7bf2efa37f60bb36555508451bc46546c92b3b1899859040453072802e54ba9fd59238fed106553d
6
+ metadata.gz: 29d1843324f9737a005b4a73e885eb7d72bc73729ce61f1dca81b895dffedaf59ab2c744c6f85747b2d9821486c94d977c996d0c0b766845a82f45b159d03b08
7
+ data.tar.gz: 812ea387dbe8da2ba18f80c8d067b04e2bc0915f1b7d886b63fcb7c2c810bfda1c7eb7b69f1a139134baefc1d8f842102c515cbb2a842e3b23f75f2179973063
@@ -5,6 +5,9 @@ require 'solr_wrapper/md5'
5
5
  require 'solr_wrapper/downloader'
6
6
  require 'solr_wrapper/instance'
7
7
  require 'solr_wrapper/client'
8
+ require 'solr_wrapper/runner'
9
+ require 'solr_wrapper/popen_runner'
10
+ require 'solr_wrapper/popen4_runner'
8
11
 
9
12
  module SolrWrapper
10
13
  def self.default_solr_version
@@ -9,6 +9,7 @@ require 'tmpdir'
9
9
  require 'zip'
10
10
  require 'erb'
11
11
  require 'yaml'
12
+ require 'retriable'
12
13
 
13
14
  module SolrWrapper
14
15
  class Instance
@@ -148,6 +149,10 @@ module SolrWrapper
148
149
  create_options[:n] = options[:config_name] if options[:config_name]
149
150
  create_options[:d] = options[:dir] if options[:dir]
150
151
 
152
+ Retriable.retriable do
153
+ raise "Not started yet" unless started?
154
+ end
155
+
151
156
  # short-circuit if we're using persisted data with an existing core/collection
152
157
  return if options[:persist] && create_options[:c] && client.exists?(create_options[:c])
153
158
 
@@ -307,51 +312,12 @@ module SolrWrapper
307
312
  # @example start solr in cloud mode on port 8983
308
313
  # exec('start', {p: '8983', c: true})
309
314
  def exec(cmd, options = {})
310
- silence_output = !options.delete(:output)
311
-
312
- args = [config.solr_binary, cmd] + config.solr_options.merge(options).map do |k, v|
313
- case v
314
- when true
315
- "-#{k}"
316
- when false, nil
317
- # don't return anything
318
- else
319
- ["-#{k}", "#{v}"]
320
- end
321
- end.flatten.compact
322
-
323
- if IO.respond_to? :popen4
324
- # JRuby
325
- env_str = config.env.map { |k, v| "#{Shellwords.escape(k)}=#{Shellwords.escape(v)}" }.join(" ")
326
- pid, input, output, error = IO.popen4(env_str + " " + args.join(" "))
327
- stringio = StringIO.new
328
- if config.verbose? && !silence_output
329
- IO.copy_stream(output, $stderr)
330
- IO.copy_stream(error, $stderr)
331
- else
332
- IO.copy_stream(output, stringio)
333
- IO.copy_stream(error, stringio)
334
- end
335
-
336
- input.close
337
- output.close
338
- error.close
339
- exit_status = Process.waitpid2(pid).last
340
- else
341
- IO.popen(config.env, args + [err: [:child, :out]]) do |io|
342
- stringio = StringIO.new
343
-
344
- if config.verbose? && !silence_output
345
- IO.copy_stream(io, $stderr)
346
- else
347
- IO.copy_stream(io, stringio)
348
- end
349
-
350
- _, exit_status = Process.wait2(io.pid)
351
- end
352
- end
315
+ stringio = StringIO.new
316
+ # JRuby uses Popen4
317
+ command_runner = IO.respond_to?(:popen4) ? Popen4Runner : PopenRunner
318
+ runner = command_runner.new(cmd, options, config)
319
+ exit_status = runner.run(stringio)
353
320
 
354
- stringio.rewind
355
321
  if exit_status != 0 && cmd != 'status'
356
322
  raise "Failed to execute solr #{cmd}: #{stringio.read}. Further information may be available in #{instance_dir}/logs"
357
323
  end
@@ -0,0 +1,32 @@
1
+ module SolrWrapper
2
+ # Runs a command using popen4 (typically for JRuby)
3
+ class Popen4Runner < Runner
4
+ def run(stringio)
5
+ pid, input, output, error = IO.popen4(command)
6
+ if config.verbose? && !silence_output?
7
+ IO.copy_stream(output, $stderr)
8
+ IO.copy_stream(error, $stderr)
9
+ else
10
+ IO.copy_stream(output, stringio)
11
+ IO.copy_stream(error, stringio)
12
+ end
13
+
14
+ input.close
15
+ output.close
16
+ error.close
17
+ exit_status = Process.waitpid2(pid).last
18
+ stringio.rewind
19
+ exit_status
20
+ end
21
+
22
+ private
23
+
24
+ def command
25
+ env_str + ' ' + argument_list.join(' ')
26
+ end
27
+
28
+ def env_str
29
+ config.env.map { |k, v| "#{Shellwords.escape(k)}=#{Shellwords.escape(v)}" }.join(' ')
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ module SolrWrapper
2
+ # Runs a command using popen (typically for MRI)
3
+ class PopenRunner < Runner
4
+ def run(stringio)
5
+ exit_status = nil
6
+ IO.popen(config.env, argument_list + [err: [:child, :out]]) do |io|
7
+ if config.verbose? && !silence_output?
8
+ IO.copy_stream(io, $stderr)
9
+ else
10
+ IO.copy_stream(io, stringio)
11
+ end
12
+
13
+ _, exit_status = Process.wait2(io.pid)
14
+ end
15
+ stringio.rewind
16
+ exit_status
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ module SolrWrapper
2
+ # An abstract class for running commands in the shell
3
+ class Runner
4
+ def initialize(cmd, options, config)
5
+ @cmd = cmd
6
+ @silence_output = !options.delete(:output)
7
+ @options = options
8
+ @config = config
9
+ end
10
+
11
+ attr_reader :cmd, :options, :config
12
+
13
+ def silence_output?
14
+ @silence_output
15
+ end
16
+
17
+ private
18
+
19
+ def argument_list
20
+ [config.solr_binary, cmd] + config.solr_options.merge(options).map do |k, v|
21
+ case v
22
+ when true
23
+ "-#{k}"
24
+ when false, nil
25
+ nil
26
+ else
27
+ ["-#{k}", v.to_s]
28
+ end
29
+ end.flatten.compact
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module SolrWrapper
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency "faraday"
22
22
  spec.add_dependency "rubyzip"
23
23
  spec.add_dependency "ruby-progressbar"
24
+ spec.add_dependency "retriable"
24
25
 
25
26
  spec.add_development_dependency "bundler", "~> 1.7"
26
27
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solr_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-27 00:00:00.000000000 Z
11
+ date: 2017-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: retriable
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -162,7 +176,10 @@ files:
162
176
  - lib/solr_wrapper/downloader.rb
163
177
  - lib/solr_wrapper/instance.rb
164
178
  - lib/solr_wrapper/md5.rb
179
+ - lib/solr_wrapper/popen4_runner.rb
180
+ - lib/solr_wrapper/popen_runner.rb
165
181
  - lib/solr_wrapper/rake_task.rb
182
+ - lib/solr_wrapper/runner.rb
166
183
  - lib/solr_wrapper/settings.rb
167
184
  - lib/solr_wrapper/tasks/solr_wrapper.rake
168
185
  - lib/solr_wrapper/version.rb
@@ -202,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
219
  version: '0'
203
220
  requirements: []
204
221
  rubyforge_project:
205
- rubygems_version: 2.6.8
222
+ rubygems_version: 2.6.12
206
223
  signing_key:
207
224
  specification_version: 4
208
225
  summary: Solr 5 service wrapper