class CommandRunner

Attributes

env[R]

The protk environment in which to run commands

Public Class Methods

new(environment) click to toggle source
# File lib/protk/command_runner.rb, line 21
def initialize(environment)
  @env=environment
end

Public Instance Methods

run_batch(command_string,job_params,jobscript_path,autodelete) click to toggle source

Runs the given command as a background job At present this sends the job to a PBS system, but in future we might support other types of background jobs

# File lib/protk/command_runner.rb, line 55
def run_batch(command_string,job_params,jobscript_path,autodelete)
  @env.log("Creating batch file for command: #{command_string}",:info)

  if ( autodelete )
#    command_string<<";rm #{jobscript_path}"
  end

  jobid=job_params[:jobid]
  if ( job_params[:vmem]==nil)
    job_params[:vmem]="900mb"
  end
  if (job_params[:queue] ==nil )
    job_params[:queue]="lowmem"
  end

  job_script="#!/bin/bash
  #PBS -N #{jobid}
  #PBS -e pbs.#{jobid}.err 
  #PBS -o pbs.#{jobid}.log
  #PBS -l nodes=1:ppn=1,vmem=#{job_params[:vmem]}
  #PBS -q #{job_params[:queue]}
  #{command_string}"

  p File.open(jobscript_path, 'w') {|f| f.write(job_script) }

  self.run_local("qsub #{jobscript_path}")
  
end
run_local(command_string) click to toggle source

Runs the given command in a local shell

# File lib/protk/command_runner.rb, line 30
def run_local(command_string)
  @env.log("Command: #{command_string} started",:info)
  status = Open4::popen4("#{command_string} ") do |pid, stdin, stdout, stderr|
    @env.log "PID #{pid}" , :info
    
    stdout.each { |line| @env.log(line.chomp,:info) }

    stderr.each { |line| @env.log(line.chomp,:warn) }

  end
  if ( status!=0 )
    # We terminated with some error code so log as an error
    @env.log( "Command: #{command_string} exited with status #{status.to_s}",:error)
  else
    @env.log( "Command: #{command_string} exited with status #{status.to_s}",:info)      
  end
  status     
end