param! “machines”, multi: true

contribute to: “machines_found” do |machines|

stats = Hash.new { |h,k| h[k] = 0 }

machines.each do |machine_row|
  name = machine_row["name"]

  if name.nil?
    $logger.error "a machine has been found without a name : #{machine_row.pretty_inspect}"
  end
  existing = Machine.find_by_name(name)
  if existing
    existing.seen_at = Time.now()
    existing.save
    stats[:existing] += 1
    $logger.debug "updating #{name}"
  else
    new_machine = Machine.create!(name: name)
    stats[:new] += 1
    $logger.debug "new #{name}"
  end
end

# TODO maybe invalidate only if there are new machines?
@op.rails_machines!
@op.redis_machines!

stats

end