Class: Lita::Adapters::External

Inherits:
Adapter
  • Object
show all
Defined in:
lib/lita/adapters/external.rb

Instance Method Summary collapse

Constructor Details

#initializeExternal

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 |message|
    log.debug("processing inbound message from: #{message.user.mention_name}")
    robot.receive(message)
  end
end

Instance Method Details

#real_adapterObject

Raises:

  • (NotImplementedError)


14
15
16
# File 'lib/lita/adapters/external.rb', line 14

def real_adapter
  raise NotImplementedError, 'You need to instanciate the real adapter'
end

#runObject

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)
        handle_inbound_message(result.last)
      end
    rescue => error
      Lita.logger.error("Inbound message failed: #{error.class}: #{error.message}")
      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 send_messages(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_downObject



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