class PuppetDBQuery::Sync
sync node and fact data from source to destination
Attributes
destination[R]
source[R]
updater[R]
Public Class Methods
new(source, destination)
click to toggle source
# File lib/puppetdb_query/sync.rb, line 13 def initialize(source, destination) @source = source @destination = destination end
Public Instance Methods
minutely(ts, node_number)
click to toggle source
this method is called once in a minute at maximum you may override this method to update you metrics… @param ts Time from last node_properties update @param node_number Integer number of nodes
# File lib/puppetdb_query/sync.rb, line 55 def minutely(ts, node_number) logger.info "node_properties update #{node_number} nodes" \ " at timestamp: #{(ts.nil? ? '' : ts.iso8601)}" end
sync(minutes = 60, seconds = 10, seconds_back = 4)
click to toggle source
# File lib/puppetdb_query/sync.rb, line 18 def sync(minutes = 60, seconds = 10, seconds_back = 4) logger.info "syncing puppetdb nodes and facts started, running #{minutes} minutes" Timeout.timeout(60 * minutes - seconds) do @updater = PuppetDBQuery::Updater.new(source, destination) # make a full update timestamp = Time.now updater.update2 # make delta updates til our time is up loop do begin check_minutely ts = Time.now updater.update3(timestamp - seconds_back) timestamp = ts rescue Timeout::Error logger.info "syncing puppetdb nodes: now our time is up, we finish" return rescue logger.error $! end logger.info "sleep for #{seconds} seconds" sleep(seconds) end end logger.info "syncing puppetdb nodes and facts ended" rescue Timeout::Error logger.info "syncing puppetdb nodes: now our time is up, we finsh" rescue logger.error $! end
Private Instance Methods
check_minutely()
click to toggle source
# File lib/puppetdb_query/sync.rb, line 62 def check_minutely @last_minute ||= Time.now - 60 timestamp = Time.now return if timestamp - 60 < @last_minute minutely(destination.node_properties_update_timestamp, updater.source_node_properties.size) @last_minute = timestamp rescue logger.error $! end