Add example ruby client: list idle/busy worker nodes and age of last ping
authorTom Clegg <tom@clinicalfuture.com>
Fri, 13 Dec 2013 21:35:52 +0000 (13:35 -0800)
committerTom Clegg <tom@clinicalfuture.com>
Fri, 13 Dec 2013 21:35:52 +0000 (13:35 -0800)
closes #1729

doc/examples/ruby/list-active-nodes.rb [new file with mode: 0755]

diff --git a/doc/examples/ruby/list-active-nodes.rb b/doc/examples/ruby/list-active-nodes.rb
new file mode 100755 (executable)
index 0000000..7a64212
--- /dev/null
@@ -0,0 +1,13 @@
+#!/usr/bin/env ruby
+
+abort 'Error: Ruby >= 1.9.3 required.' if RUBY_VERSION < '1.9.3'
+
+require 'arvados'
+
+arv = Arvados.new
+arv.node.list[:items].each do |node|
+  if node[:crunch_worker_state] != 'down'
+    ping_age = (Time.now - Time.parse(node[:last_ping_at])).to_i rescue -1
+    puts "#{node[:uuid]} #{node[:crunch_worker_state]} #{ping_age}"
+  end
+end