pyramid_scheme 0.2.8 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -14,6 +14,7 @@ begin
14
14
  gem.add_dependency "rake", ">= 0.8.7"
15
15
  gem.add_dependency "configatron"
16
16
  gem.add_dependency "aws-s3", ">= 0.6.2"
17
+ gem.add_dependency "rush", ">= 0.6.6"
17
18
  gem.add_development_dependency "rspec", ">= 1.2.9"
18
19
  gem.add_development_dependency "yard", ">= 0"
19
20
  gem.add_development_dependency "mocha", "0.9.8"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.8
1
+ 0.3.0
@@ -11,20 +11,8 @@ module PyramidScheme
11
11
  bounce_pids
12
12
  end
13
13
 
14
- def searchd_pids
15
- ps_output = `ps ax | grep searchd`
16
- ps_output.split("\n").collect{|p| /^\s*(\d*)/.match(p)[1]}
17
- end
18
-
19
14
  def bounce_pids
20
- searchd_pids.each do |pid|
21
- begin
22
- Process.kill("HUP", pid.to_i) if pid != ""
23
- rescue Exception => e
24
- raise e unless e.message =~ /No such process/i
25
- end
26
- end
15
+ PyramidScheme::ProcessManager.bounce_searchd
27
16
  end
28
-
29
17
  end
30
18
  end
@@ -36,11 +36,13 @@ module PyramidScheme
36
36
  AWS::S3::Bucket.objects(@configuration[:bucket],
37
37
  :prefix => "#{@configuration[:prefix]}/").each do |obj|
38
38
 
39
- new_filename = File.basename(obj.key.gsub("#{@configuration[:prefix]}/", '').gsub(/\./, ".new."))
40
- destined_path = File.join(@configuration[:client_destination_path], new_filename)
41
- File.open(destined_path, 'w') do |file|
42
- AWS::S3::S3Object.stream(obj.key, @configuration[:bucket]) do |chunk|
43
- file.write chunk
39
+ unless obj.key =~ /\.new\./
40
+ new_filename = File.basename(obj.key.gsub("#{@configuration[:prefix]}/", '').gsub(/\./, ".new."))
41
+ destined_path = File.join(@configuration[:client_destination_path], new_filename)
42
+ File.open(destined_path, 'w') do |file|
43
+ AWS::S3::S3Object.stream(obj.key, @configuration[:bucket]) do |chunk|
44
+ file.write chunk
45
+ end
44
46
  end
45
47
  end
46
48
  end
@@ -21,6 +21,7 @@ module PyramidScheme
21
21
  indexer.configure
22
22
  indexer.index
23
23
  destroy_lock_file
24
+ PyramidScheme::ProcessManager.bounce_searchd
24
25
  index_provider.process_index
25
26
  end
26
27
 
@@ -0,0 +1,18 @@
1
+ module PyramidScheme
2
+ class ProcessManager
3
+ def self.searchd_pids
4
+ Rush.processes.filter(:cmdline => /searchd/)
5
+ end
6
+
7
+ def self.bounce_searchd
8
+ searchd_pids.each do |process|
9
+ begin
10
+ Process.kill("HUP", process.pid)
11
+ rescue Exception => e
12
+ raise e unless e.message =~ /No such process/i
13
+ end
14
+ end
15
+ end
16
+
17
+ end
18
+ end
@@ -1,8 +1,10 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
+ require 'rake/tasklib'
3
4
 
4
5
  require 'configatron'
5
6
  require 'aws/s3'
7
+ require 'rush'
6
8
 
7
9
  require 'pyramid_scheme/required_configuration_not_found'
8
10
 
@@ -10,6 +12,7 @@ require 'pyramid_scheme/indexer/base'
10
12
  require 'pyramid_scheme/indexer/thinking_sphinx'
11
13
  require 'pyramid_scheme/indexer/ultrasphinx'
12
14
  require 'pyramid_scheme/configuration'
15
+ require 'pyramid_scheme/process_manager'
13
16
 
14
17
  require 'pyramid_scheme/index_provider/base'
15
18
  require 'pyramid_scheme/index_provider/file_system'
@@ -8,18 +8,14 @@ describe PyramidScheme::IndexClient do
8
8
  it 'should have an index provider' do
9
9
  @client.index_provider.should_not be_nil
10
10
  end
11
-
12
- it 'should send SIGHUP to active searchd processes' do
13
- @client.expects(:searchd_pids).returns(["4345"])
14
- Process.expects(:kill).with("HUP", 4345)
15
- @client.bounce_pids
16
- end
17
11
 
18
- it 'should continue gracefully if no such process gets raise' do
19
- @client.expects(:searchd_pids).returns(["4345"])
20
- Process.expects(:kill).raises(Exception, "No Such Process").then.returns(1)
21
- lambda { @client.bounce_pids }.should_not raise_error
12
+ it 'should bounce pids after indexing' do
13
+ @client.index_provider.stubs(:retrieve_index)
14
+
15
+ PyramidScheme::ProcessManager.expects(:bounce_searchd)
16
+ @client.retrieve_index
22
17
  end
18
+
23
19
  end
24
20
 
25
21
 
@@ -5,8 +5,8 @@ describe PyramidScheme::IndexServer do
5
5
 
6
6
  before(:each) do
7
7
  @server = PyramidScheme::IndexServer.new
8
- @server.indexer.stub(:configure)
9
- @server.indexer.stub(:index)
8
+ @server.indexer.stubs(:configure)
9
+ @server.indexer.stubs(:index)
10
10
  FileUtils.mkdir_p(PyramidScheme.configuration[:server_destination_path])
11
11
  FileUtils.mkdir_p(PyramidScheme.configuration[:client_source_path])
12
12
  end
@@ -37,12 +37,12 @@ describe PyramidScheme::IndexServer do
37
37
  end
38
38
 
39
39
  it 'should touch a lock file before indexing' do
40
- FileUtils.should_receive(:touch)
40
+ FileUtils.expects(:touch)
41
41
  @server.index
42
42
  end
43
43
 
44
44
  it 'should remove the lock file after indexing' do
45
- FileUtils.should_receive(:rm_f)
45
+ FileUtils.expects(:rm_f)
46
46
  @server.index
47
47
  end
48
48
 
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe PyramidScheme::ProcessManager do
4
+ it 'should send SIGHUP to active searchd processes' do
5
+ stub_rush_process_list
6
+ Process.expects(:kill).with("HUP", @pid)
7
+ PyramidScheme::ProcessManager.bounce_searchd
8
+ end
9
+
10
+ it 'should continue gracefully if no such process gets raise' do
11
+ stub_rush_process_list
12
+ Process.expects(:kill).raises(Exception, "No Such Process").then.returns(1)
13
+ lambda { PyramidScheme::ProcessManager.bounce_searchd }.should_not raise_error
14
+ end
15
+
16
+ def stub_rush_process_list
17
+ processes = [mock]
18
+ @pid = 4345
19
+ processes[0].expects(:pid).returns(@pid)
20
+ Rush.stubs(:processes).returns(mock)
21
+ Rush.processes.expects(:filter).with(:cmdline => /searchd/).returns(processes)
22
+ end
23
+
24
+ end
data/spec/spec_helper.rb CHANGED
@@ -20,6 +20,8 @@ Spec::Runner.configure do |config|
20
20
  config.server_destination_path = '/some/server/destination'
21
21
  end
22
22
  end
23
+
24
+ config.mock_with :mocha
23
25
  end
24
26
 
25
27
  module FakeFS
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- - 8
9
- version: 0.2.8
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dan Pickett
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-23 00:00:00 -04:00
17
+ date: 2010-03-29 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -58,9 +58,23 @@ dependencies:
58
58
  type: :runtime
59
59
  version_requirements: *id003
60
60
  - !ruby/object:Gem::Dependency
61
- name: rspec
61
+ name: rush
62
62
  prerelease: false
63
63
  requirement: &id004 !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ - 6
70
+ - 6
71
+ version: 0.6.6
72
+ type: :runtime
73
+ version_requirements: *id004
74
+ - !ruby/object:Gem::Dependency
75
+ name: rspec
76
+ prerelease: false
77
+ requirement: &id005 !ruby/object:Gem::Requirement
64
78
  requirements:
65
79
  - - ">="
66
80
  - !ruby/object:Gem::Version
@@ -70,11 +84,11 @@ dependencies:
70
84
  - 9
71
85
  version: 1.2.9
72
86
  type: :development
73
- version_requirements: *id004
87
+ version_requirements: *id005
74
88
  - !ruby/object:Gem::Dependency
75
89
  name: yard
76
90
  prerelease: false
77
- requirement: &id005 !ruby/object:Gem::Requirement
91
+ requirement: &id006 !ruby/object:Gem::Requirement
78
92
  requirements:
79
93
  - - ">="
80
94
  - !ruby/object:Gem::Version
@@ -82,11 +96,11 @@ dependencies:
82
96
  - 0
83
97
  version: "0"
84
98
  type: :development
85
- version_requirements: *id005
99
+ version_requirements: *id006
86
100
  - !ruby/object:Gem::Dependency
87
101
  name: mocha
88
102
  prerelease: false
89
- requirement: &id006 !ruby/object:Gem::Requirement
103
+ requirement: &id007 !ruby/object:Gem::Requirement
90
104
  requirements:
91
105
  - - "="
92
106
  - !ruby/object:Gem::Version
@@ -96,11 +110,11 @@ dependencies:
96
110
  - 8
97
111
  version: 0.9.8
98
112
  type: :development
99
- version_requirements: *id006
113
+ version_requirements: *id007
100
114
  - !ruby/object:Gem::Dependency
101
115
  name: fakefs
102
116
  prerelease: false
103
- requirement: &id007 !ruby/object:Gem::Requirement
117
+ requirement: &id008 !ruby/object:Gem::Requirement
104
118
  requirements:
105
119
  - - "="
106
120
  - !ruby/object:Gem::Version
@@ -110,7 +124,7 @@ dependencies:
110
124
  - 1
111
125
  version: 0.2.1
112
126
  type: :development
113
- version_requirements: *id007
127
+ version_requirements: *id008
114
128
  description: Sphinx index propagtion (currently via the filesystem)
115
129
  email: dpickett@enlightsolutions.com
116
130
  executables: []
@@ -140,6 +154,7 @@ files:
140
154
  - lib/pyramid_scheme/lock/base.rb
141
155
  - lib/pyramid_scheme/lock/file.rb
142
156
  - lib/pyramid_scheme/lock/s3.rb
157
+ - lib/pyramid_scheme/process_manager.rb
143
158
  - lib/pyramid_scheme/required_configuration_not_found.rb
144
159
  - lib/pyramid_scheme/tasks.rb
145
160
  - lib/pyramid_scheme/thinking_sphinx_indexer.rb
@@ -155,6 +170,7 @@ files:
155
170
  - spec/pyramid_scheme/index_server_spec.rb
156
171
  - spec/pyramid_scheme/indexer/thinking_sphinx_spec.rb
157
172
  - spec/pyramid_scheme/indexer/ultrasphinx_spec.rb
173
+ - spec/pyramid_scheme/process_manager_spec.rb
158
174
  - spec/spec.opts
159
175
  - spec/spec_helper.rb
160
176
  - tasks/pyramid_scheme.rake
@@ -197,5 +213,6 @@ test_files:
197
213
  - spec/pyramid_scheme/index_server_spec.rb
198
214
  - spec/pyramid_scheme/indexer/thinking_sphinx_spec.rb
199
215
  - spec/pyramid_scheme/indexer/ultrasphinx_spec.rb
216
+ - spec/pyramid_scheme/process_manager_spec.rb
200
217
  - spec/pyramid_scheme.rb
201
218
  - spec/spec_helper.rb