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.
6 7 8 9 10 11 12 |
# File 'lib/lita/adapters/external.rb', line 6 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
14 15 16 |
# File 'lib/lita/adapters/external.rb', line 14 def real_adapter raise NotImplementedError, 'You need to instanciate the real adapter' end |
#run ⇒ Object
Starts the connection.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/lita/adapters/external.rb', line 19 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.}") Lita.config.robot.error_handler(error) end end end |
#send_messages(target, strings) ⇒ Object
40 41 42 |
# File 'lib/lita/adapters/external.rb', line 40 def (target, strings) rpc(:send_messages, target, strings) end |
#set_topic(target, topic) ⇒ Object
44 45 46 |
# File 'lib/lita/adapters/external.rb', line 44 def set_topic(target, topic) rpc(:set_topic, target, topic) end |
#shut_down ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/lita/adapters/external.rb', line 48 def shut_down return unless @running log.info("Shutting down") @stopping = true @thread_pool.shutdown robot.trigger(:disconnected) end |