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

Returns a new instance of Sync.



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

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

Instance Method Details

#sync(minutes = 5, seconds = 10) ⇒ Object



17
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
# File 'lib/puppetdb_query/sync.rb', line 17

def sync(minutes = 5, seconds = 10)
  logger.info "syncing puppetdb nodes and facts started"

  Timeout.timeout(60 * minutes - seconds) do
    updater = PuppetDBQuery::Updater.new(source, destination)

    updater.update_node_properties

    # make a full update
    timestamp = Time.now
    updater.update2

    # make delta updates til our time is up
    loop do
      begin
        ts = Time.now
        updater.update3(timestamp - 2)
        timestamp = ts
      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