flying-sphinx 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENCE +20 -0
- data/README.textile +3 -0
- data/VERSION +1 -0
- data/lib/flying-sphinx.rb +1 -0
- data/lib/flying_sphinx.rb +10 -0
- data/lib/flying_sphinx/api.rb +29 -0
- data/lib/flying_sphinx/configuration.rb +25 -0
- data/lib/flying_sphinx/index_request.rb +29 -0
- data/lib/flying_sphinx/railtie.rb +5 -0
- data/lib/flying_sphinx/tasks.rb +9 -0
- data/lib/flying_sphinx/tunnel.rb +49 -0
- data/spec/flying_sphinx/configuration_spec.rb +45 -0
- data/spec/flying_sphinx/index_request_spec.rb +29 -0
- metadata +221 -0
data/LICENCE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Pat Allan
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'flying_sphinx'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class FlyingSphinx::API
|
2
|
+
include HTTParty
|
3
|
+
|
4
|
+
APIServer = 'http://flying-sphinx.com/heroku'
|
5
|
+
|
6
|
+
attr_reader :api_key, :heroku_id
|
7
|
+
|
8
|
+
def initialize(api_key, heroku_id)
|
9
|
+
@api_key = api_key
|
10
|
+
@heroku_id = heroku_id
|
11
|
+
end
|
12
|
+
|
13
|
+
def get(path, data = {})
|
14
|
+
self.class.get "#{APIServer}#{path}", :query => data.merge(api_options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def post(path, data = {})
|
18
|
+
self.class.post "#{APIServer}#{path}", :body => data.merge(api_options)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def api_options
|
24
|
+
{
|
25
|
+
:api_key => api_key,
|
26
|
+
:heroku_id => heroku_id
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class FlyingSphinx::Configuration
|
2
|
+
attr_reader :heroku_id, :api_key, :host, :port, :database_port
|
3
|
+
|
4
|
+
def initialize(heroku_id, api_key)
|
5
|
+
@heroku_id = heroku_id
|
6
|
+
@api_key = api_key
|
7
|
+
|
8
|
+
set_from_server
|
9
|
+
end
|
10
|
+
|
11
|
+
def api
|
12
|
+
@api ||= FlyingSphinx::API.new(api_key, heroku_id)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def set_from_server
|
18
|
+
body = api.get '/app'
|
19
|
+
json = JSON.parse(body)
|
20
|
+
|
21
|
+
@host = json['server']
|
22
|
+
@port = json['port']
|
23
|
+
@database_port = json['database_port']
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class FlyingSphinx::IndexRequest
|
2
|
+
attr_reader :configuration, :index_id
|
3
|
+
|
4
|
+
def initialize(configuration)
|
5
|
+
@configuration = configuration
|
6
|
+
|
7
|
+
FlyingSphinx::Tunnel.connect(configuration) do
|
8
|
+
begin_request
|
9
|
+
|
10
|
+
while !request_complete?
|
11
|
+
sleep(0.25)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def begin_request
|
19
|
+
@index_id = api.post('/app/indices')
|
20
|
+
end
|
21
|
+
|
22
|
+
def request_complete?
|
23
|
+
api.get("/app/indices/#{index_id}") == 'FINISHED'
|
24
|
+
end
|
25
|
+
|
26
|
+
def api
|
27
|
+
configuration.api
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class FlyingSphinx::Tunnel
|
2
|
+
def self.connect(configuration)
|
3
|
+
tunnel = new configuration
|
4
|
+
tunnel.open
|
5
|
+
tunnel.forward
|
6
|
+
|
7
|
+
yield
|
8
|
+
|
9
|
+
tunnel.close
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(configuration)
|
13
|
+
@configuration = configuration
|
14
|
+
end
|
15
|
+
|
16
|
+
def open
|
17
|
+
@session = Net::SSH.start(@configuration.host, 'sphinx', ssh_options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def forward
|
21
|
+
@session.forward.remote(
|
22
|
+
db_port, db_host, @configuration.database_port, '0.0.0.0'
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def close
|
27
|
+
@session.close
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def db_host
|
33
|
+
db_config['host']
|
34
|
+
end
|
35
|
+
|
36
|
+
def db_port
|
37
|
+
db_config['port']
|
38
|
+
end
|
39
|
+
|
40
|
+
def db_config
|
41
|
+
@db_config ||= YAML.load(open(Rails.root.join("heroku_env.yml")))['db']
|
42
|
+
end
|
43
|
+
|
44
|
+
def ssh_options
|
45
|
+
{:keys => [
|
46
|
+
File.expand_path('../../../keys/key', __FILE__)
|
47
|
+
]}
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FlyingSphinx::Configuration do
|
4
|
+
describe '#initialize' do
|
5
|
+
let(:api_server) { 'http://flying-sphinx.com/heroku' }
|
6
|
+
let(:api_key) { 'foo-bar-baz' }
|
7
|
+
let(:heroku_id) { 'app@heroku.com' }
|
8
|
+
let(:encoded_heroku_id) {
|
9
|
+
FakeWeb::Utility.encode_unsafe_chars_in_userinfo heroku_id
|
10
|
+
}
|
11
|
+
|
12
|
+
before :each do
|
13
|
+
FakeWeb.register_uri(:get,
|
14
|
+
"#{api_server}/app?api_key=#{api_key}&heroku_id=#{encoded_heroku_id}",
|
15
|
+
:body => JSON.dump(
|
16
|
+
:server => 'foo.bar.com',
|
17
|
+
:port => 9319,
|
18
|
+
:database_port => 10001
|
19
|
+
)
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "requests details from the server with the given API key" do
|
24
|
+
FlyingSphinx::Configuration.new heroku_id, api_key
|
25
|
+
|
26
|
+
FakeWeb.should have_requested :get,
|
27
|
+
"#{api_server}/app?api_key=#{api_key}&heroku_id=#{encoded_heroku_id}"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "sets the host from the server information" do
|
31
|
+
config = FlyingSphinx::Configuration.new heroku_id, api_key
|
32
|
+
config.host.should == 'foo.bar.com'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "sets the port from the server information" do
|
36
|
+
config = FlyingSphinx::Configuration.new heroku_id, api_key
|
37
|
+
config.port.should == 9319
|
38
|
+
end
|
39
|
+
|
40
|
+
it "sets the port from the server information" do
|
41
|
+
config = FlyingSphinx::Configuration.new heroku_id, api_key
|
42
|
+
config.database_port.should == 10001
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FlyingSphinx::IndexRequest do
|
4
|
+
let(:api) { FlyingSphinx::API.new 'foo', 'bar' }
|
5
|
+
let(:configuration) { stub(:configuration, :api => api) }
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
FlyingSphinx::Tunnel.stub(:connect) { |config, block| block.call }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#initialize' do
|
12
|
+
it "makes a new request" do
|
13
|
+
api.should_receive(:post).with('/app/indices').and_return(42)
|
14
|
+
api.should_receive(:get).with('/app/indices/42').and_return('PENDING')
|
15
|
+
|
16
|
+
begin
|
17
|
+
Timeout::timeout(0.2) { FlyingSphinx::IndexRequest.new(configuration) }
|
18
|
+
rescue Timeout::Error
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should finish when the index request has been completed" do
|
23
|
+
api.should_receive(:post).with('/app/indices').and_return(42)
|
24
|
+
api.should_receive(:get).with('/app/indices/42').and_return('FINISHED')
|
25
|
+
|
26
|
+
FlyingSphinx::IndexRequest.new(configuration)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,221 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flying-sphinx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Pat Allan
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-11 00:00:00 +11:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: thinking-sphinx
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: net-ssh
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 33
|
44
|
+
segments:
|
45
|
+
- 2
|
46
|
+
- 0
|
47
|
+
- 23
|
48
|
+
version: 2.0.23
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: json
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 11
|
60
|
+
segments:
|
61
|
+
- 1
|
62
|
+
- 4
|
63
|
+
- 6
|
64
|
+
version: 1.4.6
|
65
|
+
type: :runtime
|
66
|
+
version_requirements: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: httparty
|
69
|
+
prerelease: false
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 5
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
- 6
|
79
|
+
- 1
|
80
|
+
version: 0.6.1
|
81
|
+
type: :runtime
|
82
|
+
version_requirements: *id004
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: jeweler
|
85
|
+
prerelease: false
|
86
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - "="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
hash: 1
|
92
|
+
segments:
|
93
|
+
- 1
|
94
|
+
- 5
|
95
|
+
- 1
|
96
|
+
version: 1.5.1
|
97
|
+
type: :development
|
98
|
+
version_requirements: *id005
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: rspec
|
101
|
+
prerelease: false
|
102
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - "="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 11
|
108
|
+
segments:
|
109
|
+
- 2
|
110
|
+
- 1
|
111
|
+
- 0
|
112
|
+
version: 2.1.0
|
113
|
+
type: :development
|
114
|
+
version_requirements: *id006
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: rcov
|
117
|
+
prerelease: false
|
118
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - "="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
hash: 43
|
124
|
+
segments:
|
125
|
+
- 0
|
126
|
+
- 9
|
127
|
+
- 8
|
128
|
+
version: 0.9.8
|
129
|
+
type: :development
|
130
|
+
version_requirements: *id007
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: fakeweb
|
133
|
+
prerelease: false
|
134
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
135
|
+
none: false
|
136
|
+
requirements:
|
137
|
+
- - "="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
hash: 27
|
140
|
+
segments:
|
141
|
+
- 1
|
142
|
+
- 3
|
143
|
+
- 0
|
144
|
+
version: 1.3.0
|
145
|
+
type: :development
|
146
|
+
version_requirements: *id008
|
147
|
+
- !ruby/object:Gem::Dependency
|
148
|
+
name: fakeweb-matcher
|
149
|
+
prerelease: false
|
150
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
151
|
+
none: false
|
152
|
+
requirements:
|
153
|
+
- - "="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
hash: 27
|
156
|
+
segments:
|
157
|
+
- 1
|
158
|
+
- 2
|
159
|
+
- 2
|
160
|
+
version: 1.2.2
|
161
|
+
type: :development
|
162
|
+
version_requirements: *id009
|
163
|
+
description: Hooks Thinking Sphinx into the Flying Sphinx service
|
164
|
+
email: pat@freelancing-gods.com
|
165
|
+
executables: []
|
166
|
+
|
167
|
+
extensions: []
|
168
|
+
|
169
|
+
extra_rdoc_files:
|
170
|
+
- README.textile
|
171
|
+
files:
|
172
|
+
- LICENCE
|
173
|
+
- README.textile
|
174
|
+
- VERSION
|
175
|
+
- lib/flying-sphinx.rb
|
176
|
+
- lib/flying_sphinx.rb
|
177
|
+
- lib/flying_sphinx/api.rb
|
178
|
+
- lib/flying_sphinx/configuration.rb
|
179
|
+
- lib/flying_sphinx/index_request.rb
|
180
|
+
- lib/flying_sphinx/railtie.rb
|
181
|
+
- lib/flying_sphinx/tasks.rb
|
182
|
+
- lib/flying_sphinx/tunnel.rb
|
183
|
+
- spec/flying_sphinx/configuration_spec.rb
|
184
|
+
- spec/flying_sphinx/index_request_spec.rb
|
185
|
+
has_rdoc: true
|
186
|
+
homepage: http://flying-sphinx.com
|
187
|
+
licenses: []
|
188
|
+
|
189
|
+
post_install_message:
|
190
|
+
rdoc_options: []
|
191
|
+
|
192
|
+
require_paths:
|
193
|
+
- lib
|
194
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
195
|
+
none: false
|
196
|
+
requirements:
|
197
|
+
- - ">="
|
198
|
+
- !ruby/object:Gem::Version
|
199
|
+
hash: 3
|
200
|
+
segments:
|
201
|
+
- 0
|
202
|
+
version: "0"
|
203
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
204
|
+
none: false
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
hash: 3
|
209
|
+
segments:
|
210
|
+
- 0
|
211
|
+
version: "0"
|
212
|
+
requirements: []
|
213
|
+
|
214
|
+
rubyforge_project:
|
215
|
+
rubygems_version: 1.3.7
|
216
|
+
signing_key:
|
217
|
+
specification_version: 3
|
218
|
+
summary: Sphinx in the Cloud
|
219
|
+
test_files:
|
220
|
+
- spec/flying_sphinx/configuration_spec.rb
|
221
|
+
- spec/flying_sphinx/index_request_spec.rb
|