Class: ProxyMgr::Haproxy::Updater
- Inherits:
-
Object
- Object
- ProxyMgr::Haproxy::Updater
- Includes:
- Logging
- Defined in:
- lib/proxymgr/haproxy/updater.rb
Defined Under Namespace
Classes: Set
Instance Method Summary collapse
-
#initialize(socket) ⇒ Updater
constructor
A new instance of Updater.
- #produce_changeset(watchers) ⇒ Object
Methods included from Logging
Constructor Details
#initialize(socket) ⇒ Updater
Returns a new instance of Updater.
6 7 8 9 |
# File 'lib/proxymgr/haproxy/updater.rb', line 6 def initialize(socket) @socket = socket @old_watchers = {} end |
Instance Method Details
#produce_changeset(watchers) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/proxymgr/haproxy/updater.rb', line 11 def produce_changeset(watchers) if @socket and @socket.connected? new_state = Hash[watchers.map do |name, watcher| [name, watcher.servers] end] proxy_state = haproxy_state restart_needed = false (proxy_state.keys + new_state.keys).uniq.each do |name| if @old_watchers[name] and watchers[name] restart_needed = @old_watchers[name] != watchers[name] else restart_needed = true end break if restart_needed end changeset = Set.new(restart_needed, {}, {}) diff(new_state, proxy_state, changeset) unless restart_needed @old_watchers = watchers changeset else logger.debug 'No socket, not doing diffing' Set.new(true, {}, {}) end end |