class Lita::Adapters::External
Public Class Methods
new(*)
click to toggle source
Calls superclass method
# File lib/lita/adapters/external.rb, line 8 def initialize(*) super @thread_pool = ::Puma::ThreadPool.new((config.min_threads || 8).to_i, (config.max_threads || 16).to_i) do |message| log.debug("processing inbound message from: #{message.user.mention_name}") robot.receive(message) end end
Public Instance Methods
real_adapter()
click to toggle source
# File lib/lita/adapters/external.rb, line 16 def real_adapter raise NotImplementedError, 'You need to instanciate the real adapter' end
run()
click to toggle source
Starts the connection.
# File lib/lita/adapters/external.rb, line 21 def run return if @running || @stopping robot.trigger(:worker_loaded) @running = true @stopping = false log.info("Listening to redis queue: `messages:inbound`") robot.trigger(:connected) until @stopping begin if result = Lita::External.blocking_redis.blpop('messages:inbound', timeout: 1) handle_inbound_message(result.last) end rescue => error Lita.logger.error("Inbound message failed: #{error.class}: #{error.message}") if Lita.config.robot.error_handler case Lita.config.robot.error_handler.arity when 1, -1 Lita.config.robot.error_handler.call(error) when 2, -2 Lita.config.robot.error_handler.call(error, {}) end end end end end
send_messages(target, strings)
click to toggle source
# File lib/lita/adapters/external.rb, line 49 def send_messages(target, strings) rpc(:send_messages, target, strings) end
set_topic(target, topic)
click to toggle source
# File lib/lita/adapters/external.rb, line 53 def set_topic(target, topic) rpc(:set_topic, target, topic) end
shut_down()
click to toggle source
# File lib/lita/adapters/external.rb, line 57 def shut_down return unless @running log.info("Shutting down") @stopping = true @thread_pool.shutdown robot.trigger(:disconnected) end
Private Instance Methods
handle_inbound_message(payload)
click to toggle source
# File lib/lita/adapters/external.rb, line 68 def handle_inbound_message(payload) message = ::Lita::External.load_message(payload, robot: robot) log.debug("enqueuing inbound message from: #{message.user.mention_name}") @thread_pool << message end
rpc(method, *args)
click to toggle source
# File lib/lita/adapters/external.rb, line 74 def rpc(method, *args) Lita.logger.info("Putting outbound message into the queue: #{method}(#{args.map(&:inspect).join(', ')})") Lita.redis.rpush('messages:outbound', Marshal.dump([method, args])) end