lib/moleculer/registry.rb in moleculer-0.2.0 vs lib/moleculer/registry.rb in moleculer-0.3.0
- old
+ new
@@ -40,16 +40,22 @@
def length
@nodes.length
end
def active_nodes
- @nodes.values.select { |node| (Time.now - node[:node].last_heartbeat_at) < @heartbeat_interval * 3 }
+ @nodes.values.select { |node| (Time.now - node[:node].last_heartbeat_at) < expiration_interval }
end
def expired_nodes
- @nodes.values.select { |node| (Time.now - node[:node].last_heartbeat_at) > 600 }
+ @nodes.values.select { |node| (Time.now - node[:node].last_heartbeat_at) > expiration_interval }
end
+
+ private
+
+ def expiration_interval
+ @heartbeat_interval * 3
+ end
end
##
# @private
class ActionList
@@ -87,12 +93,12 @@
@heartbeat_interval = heartbeat_interval
@services = Concurrent::Hash.new
end
def add_service(service)
- @services[service.service_name] ||= NodeList.new(@heartbeat_interval)
- @services[service.service_name].add_node(service.node)
+ @services[service.full_name] ||= NodeList.new(@heartbeat_interval)
+ @services[service.full_name].add_node(service.node)
end
def fetch_nodes
@services.values.map(&:fetch_next_node)
end
@@ -128,11 +134,11 @@
end
def fetch_events(event_name)
return [] unless @events[event_name]
- @events[event_name].fetch_nodes.map { |n| n.events[event_name] }.flatten.uniq { |e| e.service.service_name }
+ @events[event_name].fetch_nodes.map { |n| n.events[event_name] }.flatten.uniq { |e| e.service.full_name }
end
end
private_constant :ActionList
private_constant :EventList
@@ -315,11 +321,11 @@
@logger.debug "registered #{node.events.length} event(s) for node '#{node.id}'"
end
def update_services(node)
node.services.values.each do |service|
- @services[service.service_name] ||= NodeList.new(@heartbeat_interval)
- @services[service.service_name].add_node(node)
+ @services[service.full_name] ||= NodeList.new(@heartbeat_interval)
+ @services[service.full_name].add_node(node)
end
end
end
end