class FetcherDsl::Fetcher
Attributes
name[RW]
period[RW]
processor[RW]
publisher[RW]
Public Class Methods
new(&block)
click to toggle source
# File lib/fetcher_dsl/fetcher.rb, line 7 def initialize(&block) @publisher = Redis.new(host:"redis") @period=0 instance_eval(&block) end
Public Instance Methods
delay(value)
click to toggle source
# File lib/fetcher_dsl/fetcher.rb, line 30 def delay(value) @period=value end
process(&block)
click to toggle source
# File lib/fetcher_dsl/fetcher.rb, line 22 def process(&block) @processor = block end
publish(keys,value)
click to toggle source
# File lib/fetcher_dsl/fetcher.rb, line 26 def publish(keys,value) @publisher.publish channel_name(keys), value end
run()
click to toggle source
# File lib/fetcher_dsl/fetcher.rb, line 34 def run loop { instance_eval(&@processor) @publisher.hmset("fetcher_next_run", @name, (Time.now+period).to_i) sleep(@period) } end
Private Instance Methods
channel_name(keys)
click to toggle source
# File lib/fetcher_dsl/fetcher.rb, line 43 def channel_name(keys) unless keys.kind_of?(Array) keys=keys.scan(/.{3}/) if keys.length==6 end ["cryptoclock","ticker",[@name,keys].flatten.join("_")].join(":").downcase end