Class: PuppetDBQuery::Sync

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/puppetdb_query/sync.rb

Overview

sync node and fact data from source to destination

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

included, #logger, #logger=

Constructor Details

#initialize(source, destination) ⇒ Sync



13
14
15
16
# File 'lib/puppetdb_query/sync.rb', line 13

def initialize(source, destination)
  @source = source
  @destination = destination
end

Instance Attribute Details

#destinationObject (readonly)

Returns the value of attribute destination.



10
11
12
# File 'lib/puppetdb_query/sync.rb', line 10

def destination
  @destination
end

#sourceObject (readonly)

Returns the value of attribute source.



9
10
11
# File 'lib/puppetdb_query/sync.rb', line 9

def source
  @source
end

#updaterObject (readonly)

Returns the value of attribute updater.



11
12
13
# File 'lib/puppetdb_query/sync.rb', line 11

def updater
  @updater
end

Instance Method Details

#minutely(ts, node_number) ⇒ Object

this method is called once in a minute at maximum you may override this method to update you metrics…



55
56
57
58
# 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) ⇒ Object



18
19
20
21
22
23
24
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
# 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