solr_wrapper 0.9.1 → 0.9.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
  SHA1:
3
- metadata.gz: d57530a891dcb0e5a17da665b949b8b941dd59ba
4
- data.tar.gz: c572a382099a877b347e2646a5c768a1cdf60c76
3
+ metadata.gz: 355fb4da1493c8acef5c50b5592fbe773c220bf2
4
+ data.tar.gz: 028aaa504c0253da58d78ad498bdfe45849c0795
5
5
  SHA512:
6
- metadata.gz: 247b9f2dfd93ec8518b9a6d38310c6019cbe4f1e524d75078b0c116d661b4783954e0962f89d930b7686e2e6be29dc7f6f26a658a81635425240cdf4b94cefb2
7
- data.tar.gz: 47c717d155ba07b715bd888ac3f20ee19f93c4d4fb4886857fecb73e530916323f1759a4b3da63f4cef7ec2f7dcf600dddb8c42f2e98f6cc56a97b958caca6a1
6
+ metadata.gz: 5852f71aa91dca84cc24c4587a0300c3cafc218e621d6400a1a21eeab070a659dfa2f81a88417f347af032a9606ad850633548a1079a42cf113244fefcf185be
7
+ data.tar.gz: 78bc51949c8bf5c2a1dfa107a01144f748e4a3b834b9602fad88ad01785c20e5e74fcf1ea0ce48ef1081681baf79e9ca12d73e74414484206ee65d0db9177ef2
data/.rubocop.yml CHANGED
@@ -10,4 +10,7 @@ Metrics/LineLength:
10
10
 
11
11
  # Offense count: 61
12
12
  Metrics/AbcSize:
13
- Max: 59
13
+ Max: 59
14
+
15
+ Style/RescueModifier:
16
+ Enabled: false
data/exe/solr_wrapper CHANGED
@@ -74,9 +74,7 @@ instance.wrap do |conn|
74
74
  conn.with_collection(collection_options) do
75
75
  $stderr.puts "http://#{instance.host}:#{instance.port}/solr/"
76
76
  begin
77
- while conn.status
78
- sleep 1
79
- end
77
+ conn.wait
80
78
  rescue Interrupt
81
79
  $stderr.puts "Solr is shutting down."
82
80
  end
@@ -99,6 +99,10 @@ module SolrWrapper
99
99
  Configuration.slice(convert_keys(hash), :name, :dir)
100
100
  end
101
101
 
102
+ def poll_interval
103
+ options.fetch(:poll_interval, 1)
104
+ end
105
+
102
106
  private
103
107
 
104
108
  def self.slice(source, *keys)
@@ -12,7 +12,7 @@ require 'yaml'
12
12
 
13
13
  module SolrWrapper
14
14
  class Instance
15
- attr_reader :config, :md5, :pid
15
+ attr_reader :config, :md5
16
16
 
17
17
  ##
18
18
  # @param [Hash] options
@@ -75,7 +75,7 @@ module SolrWrapper
75
75
 
76
76
  # Wait for solr to start
77
77
  unless status
78
- sleep 1
78
+ sleep config.poll_interval
79
79
  end
80
80
  end
81
81
  end
@@ -84,15 +84,9 @@ module SolrWrapper
84
84
  # Stop Solr and wait for it to finish exiting
85
85
  def stop
86
86
  if config.managed? && started?
87
-
88
87
  exec('stop', p: port)
89
- # Wait for solr to stop
90
- while status
91
- sleep 1
92
- end
88
+ wait
93
89
  end
94
-
95
- @pid = nil
96
90
  end
97
91
 
98
92
  ##
@@ -114,12 +108,31 @@ module SolrWrapper
114
108
  false
115
109
  end
116
110
 
111
+ def pid
112
+ return unless config.managed?
113
+
114
+ @pid ||= begin
115
+ out = exec('status').read
116
+ out.match(/process (?<pid>\d+) running on port #{port}/) do |m|
117
+ m[:pid].to_i
118
+ end
119
+ end
120
+ rescue
121
+ nil
122
+ end
123
+
117
124
  ##
118
125
  # Is Solr running?
119
126
  def started?
120
127
  !!status
121
128
  end
122
129
 
130
+ def wait
131
+ while (Process.getpgid(pid) rescue status)
132
+ sleep config.poll_interval
133
+ end
134
+ end
135
+
123
136
  ##
124
137
  # Create a new collection in solr
125
138
  # @param [Hash] options
@@ -305,7 +318,6 @@ module SolrWrapper
305
318
  # JRuby
306
319
  env_str = config.env.map { |k, v| "#{Shellwords.escape(k)}=#{Shellwords.escape(v)}" }.join(" ")
307
320
  pid, input, output, error = IO.popen4(env_str + " " + args.join(" "))
308
- @pid = pid
309
321
  stringio = StringIO.new
310
322
  if config.verbose? && !silence_output
311
323
  IO.copy_stream(output, $stderr)
@@ -318,7 +330,7 @@ module SolrWrapper
318
330
  input.close
319
331
  output.close
320
332
  error.close
321
- exit_status = Process.waitpid2(@pid).last
333
+ exit_status = Process.waitpid2(pid).last
322
334
  else
323
335
  IO.popen(config.env, args + [err: [:child, :out]]) do |io|
324
336
  stringio = StringIO.new
@@ -329,8 +341,6 @@ module SolrWrapper
329
341
  IO.copy_stream(io, stringio)
330
342
  end
331
343
 
332
- @pid = io.pid
333
-
334
344
  _, exit_status = Process.wait2(io.pid)
335
345
  end
336
346
  end
@@ -1,3 +1,3 @@
1
1
  module SolrWrapper
2
- VERSION = '0.9.1'
2
+ VERSION = '0.9.2'
3
3
  end
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: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-14 00:00:00.000000000 Z
11
+ date: 2016-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip