Class: Grenache::Base

Inherits:
Object
  • Object
show all
Includes:
Configurable
Defined in:
lib/grenache/base.rb

Instance Method Summary collapse

Methods included from Configurable

#config, included

Instance Method Details

#announce(key, port, opts = {}, &block) ⇒ Object

Announce a specific service ‘key` available on specific `port` passed block is called when the announce is sent

Parameters:

  • key (string)

    service identifier

  • port (int)

    service port number



22
23
24
25
26
27
28
29
30
# File 'lib/grenache/base.rb', line 22

def announce(key, port, opts={}, &block)
  payload = [key,port]
  link.send 'announce', payload, opts, &block
  if config.auto_announce
    periodically(1) do
      link.send 'announce', payload, opts, &block
    end
  end
end

#lookup(key, opts = {}, &block) ⇒ Object

Lookup for a specific service ‘key` passed block is called with the result values in case of `http` backend it return the result directly

Parameters:

  • key (string)

    identifier of the service



9
10
11
12
13
14
15
# File 'lib/grenache/base.rb', line 9

def lookup(key, opts={}, &block)
  unless addr = cache.has?(key)
    addr = link.send('lookup', key, opts, &block)
    cache.save(key, addr)
  end
  addr
end