Class: RedisRepeater::Repeater
- Inherits:
-
Object
- Object
- RedisRepeater::Repeater
- Defined in:
- lib/redis_repeater/repeater.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#repeats ⇒ Object
readonly
Returns the value of attribute repeats.
-
#servers ⇒ Object
readonly
Returns the value of attribute servers.
Instance Method Summary collapse
-
#initialize(configuration, logger = nil) ⇒ Repeater
constructor
A new instance of Repeater.
- #run_forever ⇒ Object
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
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
5 6 7 |
# File 'lib/redis_repeater/repeater.rb', line 5 def logger @logger end |
#repeats ⇒ Object (readonly)
Returns the value of attribute repeats.
5 6 7 |
# File 'lib/redis_repeater/repeater.rb', line 5 def repeats @repeats end |
#servers ⇒ Object (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_forever ⇒ Object
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 |