Merge branch '12194-search-always-valid'
[arvados.git] / doc / examples / ruby / list-active-nodes.rb
1 #!/usr/bin/env ruby
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: CC-BY-SA-3.0
5
6 abort 'Error: Ruby >= 1.9.3 required.' if RUBY_VERSION < '1.9.3'
7
8 require 'arvados'
9
10 arv = Arvados.new(api_version: 'v1')
11 arv.node.list[:items].each do |node|
12   if node[:crunch_worker_state] != 'down'
13     ping_age = (Time.now - Time.parse(node[:last_ping_at])).to_i rescue -1
14     puts "#{node[:uuid]} #{node[:crunch_worker_state]} #{ping_age}"
15   end
16 end