Module: Schlep
Constant Summary collapse
- VERSION =
"0.2.2"
Instance Attribute Summary collapse
Instance Method Summary collapse
- #configure {|_self| ... } ⇒ Object
- #envelope(type, message) ⇒ Object
- #event(type, message) ⇒ Object
- #events(type, messages) ⇒ Object
- #redis ⇒ Object
- #redis_options ⇒ Object
- #reset ⇒ Object
- #serialize_message(message) ⇒ Object
- #timestamp ⇒ Object
Instance Attribute Details
#app ⇒ Object
12 13 14 |
# File 'lib/schlep.rb', line 12 def app @app ||= "" end |
#hostname ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/schlep.rb', line 44 def hostname @hostname ||= `hostname` @hostname.gsub! /\s/, "" if @hostname =~ /\s/ @hostname end |
#redis_url ⇒ Object
68 69 70 |
# File 'lib/schlep.rb', line 68 def redis_url @redis_url ||= ENV["REDIS_URL"] or ENV["REDISTOGO_URL"] end |
Instance Method Details
#configure {|_self| ... } ⇒ Object
16 17 18 |
# File 'lib/schlep.rb', line 16 def configure yield self end |
#envelope(type, message) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/schlep.rb', line 20 def envelope(type, ) { :timestamp => , :app => app, :host => hostname, :type => type, :message => () }.to_json end |
#event(type, message) ⇒ Object
30 31 32 |
# File 'lib/schlep.rb', line 30 def event(type, ) redis.rpush 'schlep', envelope(type, ) end |
#events(type, messages) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/schlep.rb', line 34 def events(type, ) .map! { | | envelope(type, ) } redis.pipelined do while .any? redis.rpush 'schlep', .pop end end end |
#redis ⇒ Object
52 53 54 |
# File 'lib/schlep.rb', line 52 def redis @redis ||= Redis.new end |
#redis_options ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/schlep.rb', line 56 def return {} unless redis_url parsed_url = URI::parse(redis_url) { :host => parsed_url.host, :port => parsed_url.port, :password => parsed_url.password } end |
#reset ⇒ Object
72 73 74 75 76 |
# File 'lib/schlep.rb', line 72 def reset %w[app hostname redis redis_url].each do |ivar| instance_variable_set "@#{ivar}", nil end end |
#serialize_message(message) ⇒ Object
78 79 80 81 |
# File 'lib/schlep.rb', line 78 def () return if [String, Fixnum, Float].index .class .to_json end |
#timestamp ⇒ Object
83 84 85 |
# File 'lib/schlep.rb', line 83 def Time.now.to_f end |