Class: InfluxdbSetup::LoadQueries

Inherits:
Command
  • Object
show all
Defined in:
lib/influxdb_setup/load_queries.rb

Instance Attribute Summary

Attributes inherited from Command

#config

Instance Method Summary collapse

Methods inherited from Command

#initialize, #log

Constructor Details

This class inherits a constructor from InfluxdbSetup::Command

Instance Method Details

#callObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/influxdb_setup/load_queries.rb', line 3

def call
  db = @config.db_name
  root = @config.build_client(db)
  url = root.send :full_url, "/cluster/configuration"
  configuration = root.send :get, url

  existing_queries = configuration["ContinuousQueries"].fetch(db, {}).each_with_object({}) do |row, acc|
    acc[row['Id']] = row['Query']
  end
  expected_queries = YAML.load_file("db/influxdb_queries.yml")

  no_change = 0
  expected_queries.each do |query|
    unless existing_queries.values.include?(query)
      log "Adding '#{query}'"
      root.query query
    else
      no_change += 1
    end
  end

  log "There were #{no_change} continuous queries that required no updates"

  existing_queries.each do |(id, query)|
    unless expected_queries.include?(query)
      log "Removing '#{query}'"
      root.query "drop continuous query #{id}"
    end
  end
end