Module: Pubsubstub

Extended by:
Mutex_m
Defined in:
lib/pubsubstub.rb,
lib/pubsubstub/event.rb,
lib/pubsubstub/action.rb,
lib/pubsubstub/channel.rb,
lib/pubsubstub/logging.rb,
lib/pubsubstub/version.rb,
lib/pubsubstub/subscriber.rb,
lib/pubsubstub/application.rb,
lib/pubsubstub/subscription.rb,
lib/pubsubstub/stream_action.rb,
lib/pubsubstub/publish_action.rb

Defined Under Namespace

Modules: Logging, RedisPubSub Classes: Action, Application, Channel, Event, PublishAction, StreamAction, Subscriber, Subscription

Constant Summary collapse

VERSION =
"0.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.channels_scrollback_sizeObject

Returns the value of attribute channels_scrollback_size.



23
24
25
# File 'lib/pubsubstub.rb', line 23

def channels_scrollback_size
  @channels_scrollback_size
end

.channels_scrollback_ttlObject

Returns the value of attribute channels_scrollback_ttl.



23
24
25
# File 'lib/pubsubstub.rb', line 23

def channels_scrollback_ttl
  @channels_scrollback_ttl
end

.error_handlerObject

Returns the value of attribute error_handler.



23
24
25
# File 'lib/pubsubstub.rb', line 23

def error_handler
  @error_handler
end

.heartbeat_frequencyObject

Returns the value of attribute heartbeat_frequency.



23
24
25
# File 'lib/pubsubstub.rb', line 23

def heartbeat_frequency
  @heartbeat_frequency
end

.loggerObject

Returns the value of attribute logger.



23
24
25
# File 'lib/pubsubstub.rb', line 23

def logger
  @logger
end

.reconnect_timeoutObject

Returns the value of attribute reconnect_timeout.



23
24
25
# File 'lib/pubsubstub.rb', line 23

def reconnect_timeout
  @reconnect_timeout
end

.redis_urlObject

Returns the value of attribute redis_url.



23
24
25
# File 'lib/pubsubstub.rb', line 23

def redis_url
  @redis_url
end

Class Method Details

.handle_error(error) ⇒ Object



52
53
54
55
# File 'lib/pubsubstub.rb', line 52

def handle_error(error)
  logger.error("Uncaught exception: #{error.class}: #{error.message}\n#{error.backtrace.join("\n\t")}\n")
  error_handler && error_handler.call(error)
end

.heartbeat_eventObject



48
49
50
# File 'lib/pubsubstub.rb', line 48

def heartbeat_event
  Event.new('ping', name: 'heartbeat', retry_after: reconnect_timeout)
end

.new_redisObject



40
41
42
# File 'lib/pubsubstub.rb', line 40

def new_redis
  Redis.new(url: redis_url)
end

.publish(channel_name, *args) ⇒ Object



26
27
28
29
# File 'lib/pubsubstub.rb', line 26

def publish(channel_name, *args)
  Channel.new(channel_name).publish(Event.new(*args))
  nil
end

.redisObject



36
37
38
# File 'lib/pubsubstub.rb', line 36

def redis
  @redis || synchronize { @redis ||= new_redis }
end

.report_errorsObject



57
58
59
60
61
62
# File 'lib/pubsubstub.rb', line 57

def report_errors
  yield
rescue => error
  handle_error(error)
  raise
end

.subscriberObject



44
45
46
# File 'lib/pubsubstub.rb', line 44

def subscriber
  @subscriber || synchronize { @subscriber ||= Subscriber.new }
end