Class: Rubyists::Leopard::NatsServiceDiscovery::Operation::Verb

Inherits:
Trailblazer::Operation
  • Object
show all
Defined in:
lib/leopard/nats_service_discovery/operation/verb.rb

Overview

Base class for $SRV.<VERB> operations.

Subclasses choose which Service API verb to invoke.

Direct Known Subclasses

Info, Ping, Stats

Instance Method Summary collapse

Instance Method Details

#collect(ctx) ⇒ Boolean

Collects responses for the subclass Service API verb.

Parameters:

  • Operation context.

Returns:

  • Whether responses were collected successfully.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/leopard/nats_service_discovery/operation/verb.rb', line 21

def collect(ctx, **)
  discovery = NatsServiceDiscovery.new(client: ctx[:client], prefix: ctx[:prefix] || DEFAULT_PREFIX)
  ctx[:responses] = public_send_verb(
    discovery,
    name: ctx[:name],
    id: ctx[:id],
    timeout: ctx[:timeout] || DEFAULT_TIMEOUT,
  )
rescue StandardError => e
  ctx[:error] = e
  false
end

#public_send_verb(_discovery) ⇒ Object (private)

Invokes the subclass-specific discovery method.

Raises:

  • when a subclass does not implement this.



39
40
41
# File 'lib/leopard/nats_service_discovery/operation/verb.rb', line 39

def public_send_verb(_discovery, **)
  raise NotImplementedError, "#{self.class} must define #public_send_verb"
end