Class: Heliosphere::Server
- Inherits:
-
Object
- Object
- Heliosphere::Server
- Defined in:
- lib/heliosphere/server.rb
Constant Summary collapse
- POLL_INTERVAL =
1
Instance Attribute Summary collapse
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #clear_index ⇒ Object
- #down? ⇒ Boolean
-
#initialize(port) ⇒ Server
constructor
A new instance of Server.
- #reindex ⇒ Object
- #start ⇒ Object
- #start_and_reindex ⇒ Object
- #stop ⇒ Object
- #up? ⇒ Boolean
- #wait(&block) ⇒ Object
Constructor Details
#initialize(port) ⇒ Server
Returns a new instance of Server.
11 12 13 |
# File 'lib/heliosphere/server.rb', line 11 def initialize(port) @port = port end |
Instance Attribute Details
#port ⇒ Object (readonly)
Returns the value of attribute port.
9 10 11 |
# File 'lib/heliosphere/server.rb', line 9 def port @port end |
Instance Method Details
#clear_index ⇒ Object
44 45 46 47 48 |
# File 'lib/heliosphere/server.rb', line 44 def clear_index Heliosphere.indexer.models.each do |model| model.remove_all_from_index end end |
#down? ⇒ Boolean
54 55 56 |
# File 'lib/heliosphere/server.rb', line 54 def down? not up? end |
#reindex ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/heliosphere/server.rb', line 31 def reindex wait(&:up?) clear_index Heliosphere.indexer.models.each do |model| model.all.each do |record| Sunspot.index(record) end end Sunspot.commit end |
#start ⇒ Object
15 16 17 18 19 |
# File 'lib/heliosphere/server.rb', line 15 def start Sunspot::Rails::Server.new.start if down? wait(&:up?) sleep POLL_INTERVAL end |
#start_and_reindex ⇒ Object
26 27 28 29 |
# File 'lib/heliosphere/server.rb', line 26 def start_and_reindex start reindex end |
#stop ⇒ Object
21 22 23 24 |
# File 'lib/heliosphere/server.rb', line 21 def stop Sunspot::Rails::Server.new.stop if up? wait(&:down?) end |
#up? ⇒ Boolean
50 51 52 |
# File 'lib/heliosphere/server.rb', line 50 def up? `netstat -an` =~ /\b#{port}\b/m end |
#wait(&block) ⇒ Object
58 59 60 |
# File 'lib/heliosphere/server.rb', line 58 def wait(&block) sleep POLL_INTERVAL until yield(self) end |