Skip to content

Commit

Permalink
Better logging around subscribers that blow up
Browse files Browse the repository at this point in the history
  • Loading branch information
karmajunkie committed Mar 27, 2014
1 parent 5c4da8b commit 1d3b6ca
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
8 changes: 8 additions & 0 deletions lib/replay.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
require 'virtus'

module Replay
def self.logger=(logger)
@logger = logger
end

def self.logger
@logger
end

class ReplayError < StandardError; end
class UndefinedKeyError < ReplayError; end
class UnhandledEventError < ReplayError; end
Expand Down
3 changes: 3 additions & 0 deletions lib/replay/event_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ module EventDecorator
def self.included(base)
base.class_eval do
include Virtus.value_object
def inspect
"#{self.class.to_s}: #{self.attributes.map{|k, v| "#{k.to_s} = #{v.to_s}"}.join(", ")}"
end
end
end
end
Expand Down
1 change: 0 additions & 1 deletion lib/replay/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ def events(mod = nil, &block)
include mod
end
end

end
end
2 changes: 1 addition & 1 deletion lib/replay/publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def self.include_essentials(base)
end

def initialize(*args)
@subscription_manager = Replay::SubscriptionManager.new()
@subscription_manager = Replay::SubscriptionManager.new(Replay.logger)
super
end

Expand Down
5 changes: 3 additions & 2 deletions lib/replay/subscription_manager.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module Replay
class SubscriptionManager

def initialize
def initialize(logger = nil)
@subscribers = []
@logger = logger
end

def add_subscriber(subscriber)
Expand All @@ -19,7 +20,7 @@ def notify_subscribers(stream_id, event)
sub.published(stream_id, event)
rescue Exception => e
#hmmmm

@logger.error "exception in event subscriber #{sub.class.to_s} while handling event stream #{stream_id} #{event.inspect}: #{e.message}\n#{e.backtrace.join("\n")}" if @logger
end
end
end
Expand Down

0 comments on commit 1d3b6ca

Please sign in to comment.