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.



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

Instance Method Details

#real_adapterObject

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/lita/adapters/external.rb', line 16

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

#runObject

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)
        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) ⇒ Object



49
50
51
# File 'lib/lita/adapters/external.rb', line 49

def send_messages(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_downObject



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