Class: BaseChip::Cluster
- Inherits:
-
Object
- Object
- BaseChip::Cluster
- Defined in:
- lib/base_chip/cluster.rb
Instance Attribute Summary collapse
-
#ids ⇒ Object
Returns the value of attribute ids.
-
#slots ⇒ Object
Returns the value of attribute slots.
-
#slots_used ⇒ Object
Returns the value of attribute slots_used.
Attributes included from Dsl
Instance Method Summary collapse
- #available_slots ⇒ Object
-
#initialize ⇒ Cluster
constructor
A new instance of Cluster.
- #kill(id) ⇒ Object
- #kill_all ⇒ Object
- #submit(command) ⇒ Object
Methods included from Base
Methods included from Dsl
#add_child_mode_as_child, included, #inherit, #mode, #mode?, #type_plural
Constructor Details
#initialize ⇒ Cluster
Returns a new instance of Cluster.
39 40 41 42 43 44 |
# File 'lib/base_chip/cluster.rb', line 39 def initialize super @ids = [] @slots = 0 @slots_used = 0 end |
Instance Attribute Details
#ids ⇒ Object
Returns the value of attribute ids.
35 36 37 |
# File 'lib/base_chip/cluster.rb', line 35 def ids @ids end |
#slots ⇒ Object
Returns the value of attribute slots.
36 37 38 |
# File 'lib/base_chip/cluster.rb', line 36 def slots @slots end |
#slots_used ⇒ Object
Returns the value of attribute slots_used.
37 38 39 |
# File 'lib/base_chip/cluster.rb', line 37 def slots_used @slots_used end |
Instance Method Details
#available_slots ⇒ Object
46 47 48 |
# File 'lib/base_chip/cluster.rb', line 46 def available_slots @slots - @slots_used end |
#kill(id) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/base_chip/cluster.rb', line 83 def kill(id) if kill_procedure kill_procedure.call(id) elsif kill_command system "#{kill_command} #{id}" else fault "kill_procedure and kill_command for #{full_name} are both missing at time of kill. This should have been flagged on submit." unless kill_procedure or kill_command end end |
#kill_all ⇒ Object
78 79 80 81 82 |
# File 'lib/base_chip/cluster.rb', line 78 def kill_all @ids.each do |id| kill id end end |
#submit(command) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/base_chip/cluster.rb', line 50 def submit(command) fault "Cluster submission requires a way to kill spawned jobs. Please specify kill_procedure or kill_command for #{full_name}" unless @kill_procedure || @kill_command if submit_procedure return submit_procedure.call command elsif submit_command output = `#{submit_command} #{command}` if id_regex if result = id_regex.match(output) captures = result[1..-1] if id = (captures.select{|c| (c!=nil) && (c!='') }.first) @ids << id return id else fault "Regex /#{id_regex}/ matched '#{result}' but no useful capture was found in output of submit_command:\n#{output}" end else fault "Regex /#{id_regex}/ could not be matched in output of submit_command:\n#{output}" end elsif id_procedure return id_procedure.call(output) else fault "job id is required for job tracking. Please specify id_regex, id_variable or id_procedure for cluster #{full_name}" unless id_variable or id_procedure end else fault "No submit_procedure or submit_command defined for cluster #{full_name}" end end |