Class: Lepus::ProcessRegistry::RabbitmqBackend

Inherits:
Object
  • Object
show all
Includes:
Backend
Defined in:
lib/lepus/process_registry/rabbitmq_backend.rb

Overview

RabbitMQ-based backend for process registry. Publishes heartbeats to a fanout exchange for web dashboard aggregation. Also writes locally via FileBackend for local queries when aggregator is unavailable.

Constant Summary collapse

HEARTBEAT_EXCHANGE =
"lepus.heartbeat"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Backend

#update

Constructor Details

#initialize(fallback: nil) ⇒ RabbitmqBackend

Returns a new instance of RabbitmqBackend.



18
19
20
21
22
23
24
# File 'lib/lepus/process_registry/rabbitmq_backend.rb', line 18

def initialize(fallback: nil)
  @fallback = fallback || FileBackend.new
  @connection = nil
  @channel = nil
  @exchange = nil
  @mutex = Mutex.new
end

Instance Attribute Details

#fallbackObject (readonly)

Returns the value of attribute fallback.



16
17
18
# File 'lib/lepus/process_registry/rabbitmq_backend.rb', line 16

def fallback
  @fallback
end

Instance Method Details

#add(process, metrics: {}) ⇒ Object



36
37
38
39
# File 'lib/lepus/process_registry/rabbitmq_backend.rb', line 36

def add(process, metrics: {})
  @fallback.add(process)
  publish_heartbeat(process, metrics: metrics)
end

#allObject



54
55
56
# File 'lib/lepus/process_registry/rabbitmq_backend.rb', line 54

def all
  @fallback.all
end

#clearObject



62
63
64
# File 'lib/lepus/process_registry/rabbitmq_backend.rb', line 62

def clear
  @fallback.clear
end

#countObject



58
59
60
# File 'lib/lepus/process_registry/rabbitmq_backend.rb', line 58

def count
  @fallback.count
end

#delete(process) ⇒ Object



41
42
43
44
# File 'lib/lepus/process_registry/rabbitmq_backend.rb', line 41

def delete(process)
  @fallback.delete(process)
  publish_deregister(process)
end

#exists?(id) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/lepus/process_registry/rabbitmq_backend.rb', line 50

def exists?(id)
  @fallback.exists?(id)
end

#find(id) ⇒ Object



46
47
48
# File 'lib/lepus/process_registry/rabbitmq_backend.rb', line 46

def find(id)
  @fallback.find(id)
end

#pathObject



66
67
68
# File 'lib/lepus/process_registry/rabbitmq_backend.rb', line 66

def path
  @fallback.path
end

#startObject



26
27
28
29
# File 'lib/lepus/process_registry/rabbitmq_backend.rb', line 26

def start
  @fallback.start
  setup_channel_and_exchange
end

#stopObject



31
32
33
34
# File 'lib/lepus/process_registry/rabbitmq_backend.rb', line 31

def stop
  @fallback.stop
  close_channel
end