Class: Rodbot::Services::Relay

Inherits:
Object
  • Object
show all
Extended by:
Memoize
Defined in:
lib/rodbot/services/relay.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Memoize

included

Class Method Details

.urlString

URL (including port) to reach the given relay service locally

Parameters:

  • name (Symbol)

    relay service

Returns:

  • (String)

    URL



16
17
18
19
20
21
# File 'lib/rodbot/services/relay.rb', line 16

memoize def url(name)
  [
    (ENV["RODBOT_RELAY_URL_#{name.upcase}"] || 'tcp://localhost'),
    Rodbot.config(:port) + 1 + Rodbot.config(:plugin).keys.index(name)
  ].join(':')
end

Instance Method Details

#tasks(only: nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/rodbot/services/relay.rb', line 24

def tasks(only: nil)
  Rodbot.plugins.extend_relay
  extensions = Rodbot.plugins.extensions[:relay]
  extensions.select! { _1 == only.to_sym } if only
  fail Rodbot::RelayError, "no matching relay plugin configured" if extensions.none?
  extensions.map do |name, path|
    puts "Starting relay service extension #{name} on #{self.class.url(name)}"
    path.constantize.new.loops
  end.flatten
end