Class: ConsulWatcher::Destination::Jq

Inherits:
Object
  • Object
show all
Defined in:
lib/consul_watcher/destination/jq.rb

Overview

Send diff output to jq command line

Instance Method Summary collapse

Constructor Details

#initialize(destination_config) ⇒ Jq

Returns a new instance of Jq.



11
12
13
# File 'lib/consul_watcher/destination/jq.rb', line 11

def initialize(destination_config)
  initialize_variables(destination_config)
end

Instance Method Details

#defaultsObject



31
32
33
34
35
36
37
# File 'lib/consul_watcher/destination/jq.rb', line 31

def defaults
  logger = Logger.new(STDOUT)
  logger.level = Logger::INFO
  {
    logger: logger
  }
end

#send(change) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/consul_watcher/destination/jq.rb', line 15

def send(change)
  change_json = JSON.pretty_generate(change)
  Open3.popen3("/usr/bin/env jq '.'") do |stdin, stdout, stderr, wait_thr|
    { out: stdout, err: stderr }.each do |_key, stream|
      threads << Thread.new do
        until (raw_line = stream.gets).nil?
          output << raw_line.to_s
          @logger.info(raw_line.to_s) if stream
        end
      end
    end
    threads.each(&:join)
    status = wait_thr.value.success?
  end
end