lib/legion/extensions/health/runners/health.rb in lex-health-0.1.0 vs lib/legion/extensions/health/runners/health.rb in lex-health-0.1.1
- old
+ new
@@ -4,21 +4,20 @@
include Legion::Extensions::Helpers::Lex
def self.update(hostname:, **opts)
item = Legion::Data::Model::Node.where(name: hostname).first
- if item.nil?
- return { success: true, hostname: hostname, **opts } if insert(hostname: hostname, **opts)
+ return { success: insert(hostname: hostname, **opts), hostname: hostname, **opts } if item.nil?
- return { success: false, hostname: hostname, **opts }
- end
-
if opts.key?(:timestamp) && !item.values[:updated].nil? && item.values[:updated] > Time.parse(opts[:timestamp])
- return { success: false, reason: 'entry already updated', hostname: hostname, db_updated: item.values[:updated], **opts }
+ return { success: false,
+ reason: 'entry already updated',
+ hostname: hostname,
+ db_updated: item.values[:updated],
+ **opts }
end
- item.update(active: 1, status: opts[:status], name: hostname)
- { success: true, hostname: hostname, **opts }
+ { success: item.update(active: 1, status: opts[:status], name: hostname), hostname: hostname, **opts }
end
def self.insert(hostname:, status: 'unknown', **opts)
insert = { active: 1, status: status, name: hostname }
insert[:datacenter_id] = opts[:datacenter_id] if opts.key? :datacenter_id