travis-api/lib/travis/notification/publisher/redis.rb
Aakriti Gupta 65f1a29d86 Move travis-core files from /vendor to /lib.
- Re-factor
- Remove code for notifications
- Remove addons
- Remove travis-core gem.
- Ignore logs directory only
- Move core tests to spec/lib
2016-07-20 11:22:25 +02:00

51 lines
1.2 KiB
Ruby

require 'redis'
require 'multi_json'
module Travis
module Notification
module Publisher
class Redis
extend Exceptions::Handling
attr_accessor :redis, :ttl
def initialize(options = {})
@redis = options[:redis] || ::Redis.connect(url: Travis.config.redis.url)
@ttl = options[:ttl] || 10
end
def publish(event)
event = filter(event)
payload = MultiJson.encode(event)
# list = 'events:' << event[:uuid]
list = 'events'
redis.publish list, payload
# redis.pipelined do
# redis.publish list, payload
# redis.multi do
# redis.persist(list)
# redis.rpush(list, payload)
# redis.expire(list, ttl)
# end
# end
end
rescues :publish, from: Exception
def filter(value)
case value
when Array
value.map { |value| filter(value) }
when Hash
value.inject({}) { |hash, (key, value)| hash.merge(key => filter(value)) }
when String, Numeric, TrueClass, FalseClass, NilClass
value
else
nil
end
end
end
end
end
end