Class: FlyingSphinx::IndexRequest
- Inherits:
-
Object
- Object
- FlyingSphinx::IndexRequest
- Defined in:
- lib/flying_sphinx/index_request.rb
Constant Summary collapse
- INDEX_COMPLETE_CHECKING_INTERVAL =
3
Instance Attribute Summary collapse
-
#index_id ⇒ Object
readonly
Returns the value of attribute index_id.
-
#indices ⇒ Object
readonly
Returns the value of attribute indices.
Class Method Summary collapse
-
.cancel_jobs ⇒ Object
Remove all Delta jobs from the queue.
- .output_last_index ⇒ Object
Instance Method Summary collapse
-
#display_name ⇒ Object
Shows index name in Delayed::Job#name.
- #index ⇒ Object
-
#initialize(indices = []) ⇒ IndexRequest
constructor
A new instance of IndexRequest.
-
#perform ⇒ Boolean
Runs Sphinx’s indexer tool to process the index.
- #status_message ⇒ Object
Constructor Details
#initialize(indices = []) ⇒ IndexRequest
Returns a new instance of IndexRequest.
21 22 23 |
# File 'lib/flying_sphinx/index_request.rb', line 21 def initialize(indices = []) @indices = indices end |
Instance Attribute Details
#index_id ⇒ Object (readonly)
Returns the value of attribute index_id.
2 3 4 |
# File 'lib/flying_sphinx/index_request.rb', line 2 def index_id @index_id end |
#indices ⇒ Object (readonly)
Returns the value of attribute indices.
2 3 4 |
# File 'lib/flying_sphinx/index_request.rb', line 2 def indices @indices end |
Class Method Details
.cancel_jobs ⇒ Object
Remove all Delta jobs from the queue. If the delayed_jobs table does not exist, this method will do nothing.
9 10 11 12 13 |
# File 'lib/flying_sphinx/index_request.rb', line 9 def self.cancel_jobs return unless defined?(::Delayed) && ::Delayed::Job.table_exists? ::Delayed::Job.delete_all "handler LIKE '--- !ruby/object:FlyingSphinx::%'" end |
.output_last_index ⇒ Object
15 16 17 18 19 |
# File 'lib/flying_sphinx/index_request.rb', line 15 def self.output_last_index index = FlyingSphinx::Configuration.new.api.get('indices/last').body puts "Index Job Status: #{index.status}" puts "Index Log:\n#{index.log}" end |
Instance Method Details
#display_name ⇒ Object
Shows index name in Delayed::Job#name.
27 28 29 |
# File 'lib/flying_sphinx/index_request.rb', line 27 def display_name "#{self.class.name} for #{indices.join(', ')}" end |
#index ⇒ Object
31 32 33 34 35 36 |
# File 'lib/flying_sphinx/index_request.rb', line 31 def index begin_request while !request_complete? sleep 3 end end |
#perform ⇒ Boolean
Runs Sphinx’s indexer tool to process the index. Currently assumes Sphinx is running.
59 60 61 62 |
# File 'lib/flying_sphinx/index_request.rb', line 59 def perform index true end |
#status_message ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/flying_sphinx/index_request.rb', line 38 def raise "Index Request failed to start. Something's not right!" if @index_id.nil? status = request_status case status when 'FINISHED' "Index Request has completed:\n#{request_log}" when 'FAILED' 'Index Request failed.' when 'PENDING' 'Index Request is still pending - something has gone wrong.' else "Unknown index response: '#{status}'." end end |