Module: Dynopoker

Defined in:
lib/dynopoker.rb,
lib/dynopoker/rails.rb,
lib/dynopoker/railtie.rb,
lib/dynopoker/version.rb,
lib/dynopoker/configuration.rb

Defined Under Namespace

Modules: Rails Classes: Configuration, Railtie

Constant Summary collapse

VERSION =
"1.0.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.already_startedObject

Returns the value of attribute already_started.



7
8
9
# File 'lib/dynopoker.rb', line 7

def already_started
  @already_started
end

.configurationObject

Returns the value of attribute configuration.



7
8
9
# File 'lib/dynopoker.rb', line 7

def configuration
  @configuration
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Yields:



10
11
12
13
14
15
16
17
18
# File 'lib/dynopoker.rb', line 10

def self.configure
  self.configuration ||= Configuration.new
  yield configuration

  if configuration.should_poke? && !already_started
    self.already_started = true
    self.start
  end
end

.pokeObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dynopoker.rb', line 25

def self.poke
  while(true)
    begin
      configuration.logger.info "Dynopoker: poking #{self.configuration.address}"
      open(configuration.address).content_type
    rescue Exception => exception
      configuration.logger.error "Dynopoker: poking error #{exception.class.name}: #{exception.message}"
    end

    sleep(configuration.poke_frequency)
  end
end

.startObject



20
21
22
23
# File 'lib/dynopoker.rb', line 20

def self.start
  configuration.logger.info 'Dynopoker: starting thread'
  Thread.new { poke } or configuration.logger.error 'Dynopoker: error while starting thread'
end