Class: Dnsync::RecurringZoneUpdater
- Inherits:
-
Object
- Object
- Dnsync::RecurringZoneUpdater
- Defined in:
- lib/dnsync/recurring_zone_updater.rb
Instance Method Summary collapse
- #health_problems ⇒ Object
- #healthy? ⇒ Boolean
-
#initialize(source, destination, frequency) ⇒ RecurringZoneUpdater
constructor
A new instance of RecurringZoneUpdater.
- #join ⇒ Object
- #last_updated ⇒ Object
- #recently_updated?(updated = nil) ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(source, destination, frequency) ⇒ RecurringZoneUpdater
Returns a new instance of RecurringZoneUpdater.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/dnsync/recurring_zone_updater.rb', line 6 def initialize(source, destination, frequency) @source = source @destination = destination @frequency = frequency @thread = Atomic.new(nil) @running = Atomic.new(false) @last_updated_at = Atomic.new(nil) @last_exception = Atomic.new(nil) end |
Instance Method Details
#health_problems ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/dnsync/recurring_zone_updater.rb', line 48 def health_problems thread = @thread.value running = @running.value updated = last_updated exception = @last_exception.value problems = [] unless running problems << "Component not running" end unless thread && thread.alive? problems << "Thread not alive" end unless recently_updated?(updated) if updated time_description = "in %0.2f seconds (should have been %d seconds)" % [ updated.to_f, @frequency ] else time_description = "ever" end problems << "Successful update hasn't occured #{time_description}" end if exception problems << "Last update failed with #{exception.class}: #{exception.}" end unless problems.empty? problems.join('; ') end end |
#healthy? ⇒ Boolean
44 45 46 |
# File 'lib/dnsync/recurring_zone_updater.rb', line 44 def healthy? health_problems.blank? end |
#join ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/dnsync/recurring_zone_updater.rb', line 36 def join if thread = @thread.value thread.join end self end |
#last_updated ⇒ Object
88 89 90 91 92 |
# File 'lib/dnsync/recurring_zone_updater.rb', line 88 def last_updated if at = @last_updated_at.value Time.now.to_f - at.to_f end end |
#recently_updated?(updated = nil) ⇒ Boolean
83 84 85 86 |
# File 'lib/dnsync/recurring_zone_updater.rb', line 83 def recently_updated?(updated = nil) updated ||= last_updated updated && updated < (@frequency * 2) end |
#start ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dnsync/recurring_zone_updater.rb', line 17 def start if (thread = @thread.value) && thread.alive? return self end @running.value = true @last_updated_at.value = Time.now @thread.value = Thread.new do Thread.current.abort_on_exception = true run end end |
#stop ⇒ Object
31 32 33 34 |
# File 'lib/dnsync/recurring_zone_updater.rb', line 31 def stop @running.value = false self end |