Class: Elastics::ModelTasks
- Inherits:
-
Tasks
- Object
- Tasks
- Elastics::ModelTasks
- Defined in:
- lib/elastics/model_tasks.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #default_options ⇒ Object
- #import_models ⇒ Object
-
#initialize(overrides = {}) ⇒ ModelTasks
constructor
A new instance of ModelTasks.
Constructor Details
#initialize(overrides = {}) ⇒ ModelTasks
Returns a new instance of ModelTasks.
7 8 9 10 11 12 13 14 15 |
# File 'lib/elastics/model_tasks.rb', line 7 def initialize(overrides={}) = Elastics::Utils. *.keys [:timeout] = [:timeout].to_i if [:timeout] [:batch_size] = [:batch_size].to_i if [:batch_size] [:models] = [:models].split(',') if [:models] @options = .merge().merge(overrides) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/elastics/model_tasks.rb', line 5 def @options end |
Instance Method Details
#default_options ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/elastics/model_tasks.rb', line 17 def @default_options ||= { :force => false, :timeout => 60, :batch_size => 500, :models => Conf.elastics_models, :verbose => true } end |
#import_models ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/elastics/model_tasks.rb', line 25 def import_models Prompter.say_title "Import models: #{models.map(&:to_s).inspect}" if [:verbose] Conf.http_client.[:timeout] = [:timeout] deleted = [] models.each do |model| raise ArgumentError, "The model #{model.name} is not a standard Elastics::ModelIndexer model" \ unless model.include?(Elastics::ModelIndexer) index = model.elastics.index index = LiveReindex.prefix_index(index) if LiveReindex.should_prefix_index? # block never called during live-reindex, since it doesn't exist if [:force] unless deleted.include?(index) Elastics.delete_index(:index => index) deleted << index Prompter.say_warning "#{index} index deleted" if [:verbose] end end # block never called during live-reindex, since prefix_index creates it unless Elastics.indices_exists(:index => index) Conf.indices.create_index(index) Prompter.say_ok "#{index} index created" if [:verbose] end = ProgBar.new(model.count, [:batch_size], "Model #{model}: ") if [:verbose] model.elastics_in_batches(:batch_size => [:batch_size]) do |batch| result = Elastics.post_bulk_collection(batch) || next .process_result(result, batch.size) if [:verbose] end .finish if [:verbose] end end |