Class: Lita::Adapters::External
- Inherits:
-
Adapter
- Object
- Adapter
- Lita::Adapters::External
- Defined in:
- lib/lita/adapters/external.rb
Instance Method Summary collapse
-
#initialize ⇒ External
constructor
A new instance of External.
- #real_adapter ⇒ Object
-
#run ⇒ Object
Starts the connection.
- #send_messages(target, strings) ⇒ Object
- #set_topic(target, topic) ⇒ Object
- #shut_down ⇒ Object
Constructor Details
#initialize ⇒ External
Returns a new instance of External.
8 9 10 11 12 13 14 |
# 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 || log.debug("processing inbound message from: #{.user.mention_name}") robot.receive() end end |
Instance Method Details
#real_adapter ⇒ Object
16 17 18 |
# File 'lib/lita/adapters/external.rb', line 16 def real_adapter raise NotImplementedError, 'You need to instanciate the real adapter' end |
#run ⇒ Object
Starts the connection.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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) (result.last) end rescue => error Lita.logger.error("Inbound message failed: #{error.class}: #{error.}") 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) ⇒ Object
49 50 51 |
# File 'lib/lita/adapters/external.rb', line 49 def (target, strings) rpc(:send_messages, target, strings) end |
#set_topic(target, topic) ⇒ Object
53 54 55 |
# File 'lib/lita/adapters/external.rb', line 53 def set_topic(target, topic) rpc(:set_topic, target, topic) end |
#shut_down ⇒ Object
57 58 59 60 61 62 63 64 |
# 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 |