Module: Pubsubstub

Extended by:
Mutex_m
Defined in:
lib/pubsubstub.rb,
lib/pubsubstub/event.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: Application, Channel, Event, PublishAction, StreamAction, Subscriber, Subscription

Constant Summary collapse

VERSION =
"0.3.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

.use_persistent_connectionsObject

Returns the value of attribute use_persistent_connections.



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

def use_persistent_connections
  @use_persistent_connections
end

Class Method Details

.handle_error(error) ⇒ Object



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

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



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

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

.new_redisObject



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

def new_redis
  Redis.new(url: redis_url)
end

.publish(channel_name, *args) ⇒ Object



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

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

.redisObject



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

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

.redis=(client) ⇒ Object



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

def redis=(client)
  synchronize { @redis = client }
end

.report_errorsObject



62
63
64
65
66
67
# File 'lib/pubsubstub.rb', line 62

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

.subscriberObject



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

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