Class: ThinkingSphinx::Deltas::ResqueDelta::CoreIndex
- Inherits:
-
Object
- Object
- ThinkingSphinx::Deltas::ResqueDelta::CoreIndex
- Defined in:
- lib/thinking_sphinx/deltas/resque_delta/core_index.rb
Instance Method Summary collapse
-
#lock_delta(index_name) ⇒ Object
Public: Lock a delta index against indexing or new index jobs.
-
#lock_deltas ⇒ Object
Public: Lock all delta indexes against indexing or new index jobs.
-
#smart_index(opts = {}) ⇒ Object
Public: Index all indices while locking each delta as we index the corresponding core index.
-
#unlock_delta(index_name) ⇒ Object
Public: Unlock a delta index for indexing or new index jobs.
-
#unlock_deltas ⇒ Object
Public: Unlock all delta indexes for indexing or new index jobs.
-
#with_delta_index_lock(index_name) ⇒ Object
Public: Wraps the passed block with a delta index lock.
Instance Method Details
#lock_delta(index_name) ⇒ Object
Public: Lock a delta index against indexing or new index jobs.
index_name - The String index prefix.
Examples
lock_delta('foo')
Returns nothing.
11 12 13 |
# File 'lib/thinking_sphinx/deltas/resque_delta/core_index.rb', line 11 def lock_delta(index_name) ThinkingSphinx::Deltas::ResqueDelta.lock("#{index_name}_delta") end |
#lock_deltas ⇒ Object
Public: Lock all delta indexes against indexing or new index jobs.
Returns nothing.
31 32 33 |
# File 'lib/thinking_sphinx/deltas/resque_delta/core_index.rb', line 31 def lock_deltas sphinx_indices.each { |index_name| lock_delta(index_name) } end |
#smart_index(opts = {}) ⇒ Object
Public: Index all indices while locking each delta as we index the corresponding core index.
Returns true on success; false on failure.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/thinking_sphinx/deltas/resque_delta/core_index.rb', line 45 def smart_index(opts = {}) verbose = opts.fetch(:verbose, true) verbose = false if ENV['SILENT'] == 'true' # Load config like ts:in. unless ENV['INDEX_ONLY'] == 'true' puts "Generating Configuration to #{ts_config.config_file}" if verbose ts_config.build end FileUtils.mkdir_p(ts_config.searchd_file_path) # Index each core, one at a time. Wrap with delta locking logic. index_prefixes.each do |index_name| ret = nil with_delta_index_lock(index_name) do ThinkingSphinx::Deltas::ResqueDelta.prepare_for_core_index(index_name) ts_config.controller.index("#{index_name}_core", :verbose => verbose) ret = $? end return false if ret.to_i != 0 Resque.enqueue( ThinkingSphinx::Deltas::ResqueDelta::DeltaJob, "#{index_name}_delta" ) end true end |
#unlock_delta(index_name) ⇒ Object
Public: Unlock a delta index for indexing or new index jobs.
index_name - The String index prefix.
Examples
unlock_delta('foo')
Returns nothing.
24 25 26 |
# File 'lib/thinking_sphinx/deltas/resque_delta/core_index.rb', line 24 def unlock_delta(index_name) ThinkingSphinx::Deltas::ResqueDelta.unlock("#{index_name}_delta") end |
#unlock_deltas ⇒ Object
Public: Unlock all delta indexes for indexing or new index jobs.
Returns nothing.
38 39 40 |
# File 'lib/thinking_sphinx/deltas/resque_delta/core_index.rb', line 38 def unlock_deltas sphinx_indices.each { |index_name| unlock_delta(index_name) } end |
#with_delta_index_lock(index_name) ⇒ Object
Public: Wraps the passed block with a delta index lock
index_name - The String index prefix.
Examples
with_delta_index_lock('foo')
Returns nothing.
86 87 88 89 90 |
# File 'lib/thinking_sphinx/deltas/resque_delta/core_index.rb', line 86 def with_delta_index_lock(index_name) lock_delta(index_name) yield unlock_delta(index_name) end |