- sinfo.split("\n").
- each do |line|
- re = line.match /(\S+?):+(idle|alloc|down)?/
- next if !re
-
- _, node_name, node_state = *re
- node_state = 'down' unless %w(idle alloc down).include? node_state
-
- # sinfo tells us about a node N times if it is shared by N partitions
- next if node_seen[node_name]
- node_seen[node_name] = true
-
- # update our database (and cache) when a node's state changes
- if @node_state[node_name] != node_state
- @node_state[node_name] = node_state
- node = Node.where('hostname=?', node_name).order(:last_ping_at).last
- if node
- $stderr.puts "dispatch: update #{node_name} state to #{node_state}"
- node.info['slurm_state'] = node_state
- if not node.save
- $stderr.puts "dispatch: failed to update #{node.uuid}: #{node.errors.messages}"
- end
- elsif node_state != 'down'
- $stderr.puts "dispatch: sinfo reports '#{node_name}' is not down, but no node has that name"
- end
+ node = Node.where('hostname=?', hostname).order(:last_ping_at).last
+ if node
+ $stderr.puts "dispatch: update #{hostname} state to #{slurmdata}"
+ node.info["slurm_state"] = slurmdata[:state]
+ node.job_uuid = slurmdata[:job]
+ if node.save
+ @node_state[hostname] = slurmdata
+ else
+ $stderr.puts "dispatch: failed to update #{node.uuid}: #{node.errors.messages}"