Sha256: 04d2799b3777187b4588134121f73595614490807fee018a09e5da2eafa2a8b6

Contents?: true

Size: 1.41 KB

Versions: 8

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

require 'elastic_manager/logger'

# Index deleting operations
module Delete
  include Logging

  def delete_populate_indices(indices, date_from, date_to, daysago)
    result = []

    if indices.length == 1 && indices.first == '_all'
      result = @elastic.all_indices(date_from, date_to, daysago, nil, nil, @config)
    else
      if date_from.nil?
        result = @elastic.all_indices(date_from, date_to, daysago, nil, nil, @config).select { |r| r.start_with?(*indices) }
      else
        date_from.upto(date_to) do |date|
          indices.each do |index|
            date_formatted = date.to_s.tr('-', '.')
            result << "#{index}-#{date_formatted}"
          end
        end
      end
    end

    return result unless result.empty?

    log.fatal 'no indices for work'
    exit 1
  end

  def do_delete(indices)
    indices.each do |index|
      next if skip_index?(index, 'delete')

      response = @elastic.request(:get, "/_cat/indices/#{index}")

      if index_exist?(response)

        elastic_action_with_log('delete_index', index, delete_without_snapshot?(index))
      else
        log.warn "#{index} index not found"
      end
    end
  end

  def delete
    indices, date_from, date_to, daysago = prepare_vars
    prechecks(date_from, date_to)
    indices = delete_populate_indices(indices, date_from, date_to, daysago)
    log.debug indices.inspect
    do_delete(indices)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
elastic_manager-0.3.6 lib/elastic_manager/delete.rb
elastic_manager-0.3.5 lib/elastic_manager/delete.rb
elastic_manager-0.3.4 lib/elastic_manager/delete.rb
elastic_manager-0.3.3 lib/elastic_manager/delete.rb
elastic_manager-0.3.2 lib/elastic_manager/delete.rb
elastic_manager-0.3.1 lib/elastic_manager/delete.rb
elastic_manager-0.3.1.pre.debug lib/elastic_manager/delete.rb
elastic_manager-0.3.0 lib/elastic_manager/delete.rb