Class: Qmore::Persistence::Monitor

Inherits:
Object
  • Object
show all
Includes:
GemLogger::LoggerSupport
Defined in:
lib/qmore/persistence.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(persistence, interval) ⇒ Monitor

from some source (redis, file, db, etc) defaults to 1 minute

Parameters:

  • persistence (Qmore::persistence)
    • responsible for reading the configuration

  • interval (Integer)
    • the period, in seconds, to wait between updates to the configuration.



10
11
12
13
# File 'lib/qmore/persistence.rb', line 10

def initialize(persistence, interval)
  @persistence = persistence
  @interval = interval
end

Instance Attribute Details

#intervalObject (readonly)

Returns the value of attribute interval.



5
6
7
# File 'lib/qmore/persistence.rb', line 5

def interval
  @interval
end

#updatingObject (readonly)

Returns the value of attribute updating.



5
6
7
# File 'lib/qmore/persistence.rb', line 5

def updating
  @updating
end

Instance Method Details

#startObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/qmore/persistence.rb', line 15

def start
  return if @updating
  @updating = true

  # Ensure we load the configuration once from persistence before
  # the background thread.
  Qmore.configuration = @persistence.load

  Thread.new do
    while(@updating) do
      sleep @interval
      begin
        Qmore.configuration = @persistence.load
      rescue => e
        logger.error "#{e.class.name} : #{e.message}"
      end
    end
  end
end

#stopObject



35
36
37
# File 'lib/qmore/persistence.rb', line 35

def stop
  @updating = false
end