Class: Xanthus::Job
- Inherits:
-
Object
- Object
- Xanthus::Job
- Defined in:
- lib/xanthus/job.rb
Instance Attribute Summary collapse
-
#inputs ⇒ Object
Returns the value of attribute inputs.
-
#iterations ⇒ Object
Returns the value of attribute iterations.
-
#name ⇒ Object
Returns the value of attribute name.
-
#outputs ⇒ Object
Returns the value of attribute outputs.
-
#post_instructions ⇒ Object
Returns the value of attribute post_instructions.
-
#pre_instructions ⇒ Object
Returns the value of attribute pre_instructions.
-
#tasks ⇒ Object
Returns the value of attribute tasks.
Instance Method Summary collapse
- #destroy(machine) ⇒ Object
- #execute(config, iteration) ⇒ Object
- #execute_post_instructions ⇒ Object
- #execute_pre_instructions ⇒ Object
- #halt(machine) ⇒ Object
- #host_scripts(config) ⇒ Object
-
#initialize ⇒ Job
constructor
A new instance of Job.
- #output_script(machine, outputs) ⇒ Object
- #run(machine) ⇒ Object
- #setup_env(machine, scripts, config) ⇒ Object
Constructor Details
#initialize ⇒ Job
Returns a new instance of Job.
14 15 16 17 18 19 20 21 |
# File 'lib/xanthus/job.rb', line 14 def initialize @iterations = 0 @tasks = Hash.new @outputs = Hash.new @inputs = Hash.new @pre_instructions = nil @post_instructions = nil end |
Instance Attribute Details
#inputs ⇒ Object
Returns the value of attribute inputs.
10 11 12 |
# File 'lib/xanthus/job.rb', line 10 def inputs @inputs end |
#iterations ⇒ Object
Returns the value of attribute iterations.
7 8 9 |
# File 'lib/xanthus/job.rb', line 7 def iterations @iterations end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/xanthus/job.rb', line 6 def name @name end |
#outputs ⇒ Object
Returns the value of attribute outputs.
9 10 11 |
# File 'lib/xanthus/job.rb', line 9 def outputs @outputs end |
#post_instructions ⇒ Object
Returns the value of attribute post_instructions.
12 13 14 |
# File 'lib/xanthus/job.rb', line 12 def post_instructions @post_instructions end |
#pre_instructions ⇒ Object
Returns the value of attribute pre_instructions.
11 12 13 |
# File 'lib/xanthus/job.rb', line 11 def pre_instructions @pre_instructions end |
#tasks ⇒ Object
Returns the value of attribute tasks.
8 9 10 |
# File 'lib/xanthus/job.rb', line 8 def tasks @tasks end |
Instance Method Details
#destroy(machine) ⇒ Object
99 100 101 102 103 104 |
# File 'lib/xanthus/job.rb', line 99 def destroy machine Dir.chdir machine.to_s do system('vagrant', 'destroy', '-f') system('rm', '-rf', '.vagrant') end end |
#execute(config, iteration) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/xanthus/job.rb', line 106 def execute config, iteration puts "Running job #{name.to_s}-#{iteration.to_s}..." FileUtils.mkdir_p 'tmp' Dir.chdir 'tmp' do self.host_scripts config @tasks.each do |machine, templates| self.setup_env machine, templates, config end self.execute_pre_instructions unless @pre_instructions.nil? @tasks.each do |machine, templates| self.run machine end self.execute_post_instructions unless @post_instructions.nil? @tasks.each do |machine, templates| self.halt machine end @tasks.each do |machine, templates| self.destroy machine end end system('mv', 'tmp', "#{name.to_s}-#{iteration.to_s}") system('tar', '-czvf', "#{name.to_s}-#{iteration.to_s}.tar.gz", "#{name.to_s}-#{iteration.to_s}") system('rm', '-rf', "#{name.to_s}-#{iteration.to_s}") config.github_conf.add("#{name.to_s}-#{iteration.to_s}.tar.gz") unless config.github_conf.nil? config.github_conf.push unless config.github_conf.nil? config.dataverse_conf.add("#{name.to_s}-#{iteration.to_s}.tar.gz") unless config.dataverse_conf.nil? puts "Job #{name.to_s}-#{iteration.to_s} done." end |
#execute_post_instructions ⇒ Object
88 89 90 91 |
# File 'lib/xanthus/job.rb', line 88 def execute_post_instructions puts 'Running post instructions...' system('sh', './post.sh') end |
#execute_pre_instructions ⇒ Object
77 78 79 80 |
# File 'lib/xanthus/job.rb', line 77 def execute_pre_instructions puts 'Running pre instructions...' system('sh', './pre.sh') end |
#halt(machine) ⇒ Object
93 94 95 96 97 |
# File 'lib/xanthus/job.rb', line 93 def halt machine Dir.chdir machine.to_s do system('vagrant', 'halt') end end |
#host_scripts(config) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/xanthus/job.rb', line 60 def host_scripts config puts 'Setting up host scripts...' if !@pre_instructions.nil? script = Script.new(@pre_instructions, config).to_s File.open('pre.sh', 'w+') do |f| f.write(script) end end if !@post_instructions.nil? script = Script.new(@post_instructions, config).to_s File.open('post.sh', 'w+') do |f| f.write(script) end end end |
#output_script(machine, outputs) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/xanthus/job.rb', line 23 def output_script machine, outputs script = "" outputs.each do |name, path| script += "scp -P 2222 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null vagrant@localhost:#{path} output/#{name}.data\n" end return script end |
#run(machine) ⇒ Object
82 83 84 85 86 |
# File 'lib/xanthus/job.rb', line 82 def run machine Dir.chdir machine.to_s do system('vagrant', 'up') end end |
#setup_env(machine, scripts, config) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/xanthus/job.rb', line 31 def setup_env machine, scripts, config puts 'Setting up task on machine '+machine.to_s+'...' FileUtils.mkdir_p machine.to_s Dir.chdir machine.to_s do if !@inputs[machine].nil? @inputs[machine].each do |name| system('cp', '-f', "../../#{name}", "#{name}") end end FileUtils.mkdir_p 'output' puts 'Creating provision files...' File.open('Vagrantfile', 'w+') do |f| f.write(config.vms[machine].to_vagrant) end script = Script.new(scripts, config).to_s File.open('provision.sh', 'w+') do |f| f.write(script) end script = 'echo "nothing to do"' script = self.output_script(machine, @outputs[machine]) unless @outputs[machine].nil? # add simple support for Windows before_halt_hook = "before_halt.#{sys_script_ext}" File.open(before_halt_hook, 'w+') do |f| f.write(script) end system('chmod', '+x', before_halt_hook) end end |