Class: RedisRepeater::Repeater

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_repeater/repeater.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration, logger = nil) ⇒ Repeater

Returns a new instance of Repeater.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/redis_repeater/repeater.rb', line 7

def initialize(configuration, logger = nil)
  raise ConfigurationError.new 'Configuration is empty' unless configuration
  @servers = {}
  @repeats = []
  # Get the logger
  @logger = logger
  @logger ||= Logger.new(configuration['log']) if configuration['log']
  @logger ||= Logger.new(STDOUT)
  # Load the configuration and start the server
  load_hash_configuration configuration
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



5
6
7
# File 'lib/redis_repeater/repeater.rb', line 5

def logger
  @logger
end

#repeatsObject (readonly)

Returns the value of attribute repeats.



5
6
7
# File 'lib/redis_repeater/repeater.rb', line 5

def repeats
  @repeats
end

#serversObject (readonly)

Returns the value of attribute servers.



5
6
7
# File 'lib/redis_repeater/repeater.rb', line 5

def servers
  @servers
end

Instance Method Details

#run_foreverObject

Raises:



19
20
21
22
23
24
25
26
27
28
# File 'lib/redis_repeater/repeater.rb', line 19

def run_forever
  raise ConfigurationError.new('No repeat jobs specified in configuration') if @repeats.empty?
  # start the scheduler and run it forever
  EventMachine::run do
    @repeats.each do |job|
      EventMachine::add_periodic_timer(job.timeout) { job.perform }
    end
    @logger.info "Repeating #{@repeats.count} #{@repeats.count == 1 ? 'queue' : 'queues'} forever!"
  end
end