Sha256: d33e366c056f0a3cde51d104441451693ba287f284b4ec890eb14a981ca1bda3

Contents?: true

Size: 1.64 KB

Versions: 2

Compression:

Stored size: 1.64 KB

Contents

require 'rjobs/command_builder'
require 'rjobs/process'
require 'rjobs/job'

module Rjobs
  class JobHandler
    @@host = "127.0.0.1"
    @@password = "xgrid"

    def self.get_job_attributes(id)
      cb = Rjobs::CommandBuilder.new("xgrid", {
        :h => host,
        :p => password,
        :f => "xml",
        :job => :attributes,
        :id => id
      })      
      # puts cb.build
      Rjobs::Process.run(cb.build)
    end

    def self.submit_job(job)
      cb = Rjobs::CommandBuilder.new("xgrid", {
        :h => host,
        :p => password,
        :f => "xml",
        :job => :submit        
      })      
      cmd = cb.build << " " << job.command
      puts cmd

      result = Rjobs::Process.run(cmd)
      
      result = Plist::parse_xml(result)

      job.id = result['jobIdentifier'].nil? ? -1 : Integer(result['jobIdentifier'])
    end

    def self.get_job_results(job, separate_output)
      params = {
        :h => host,
        :p => password,
        :f => "xml",
        :job => :results,
        :id => job.id        
      }
      if separate_output
        if job.status == "Finished"
          params[:so] = job.name+".out"
          puts "#{job.name} --> #{params[:so]}"
        else
          params[:se] = job.name+".err"
          puts "#{job.name} --> #{params[:se]}".red
        end        
      end
      cb = Rjobs::CommandBuilder.new("xgrid", params)      
      Rjobs::Process.run(cb.build)
    end

    def self.host
      @@host
    end

    def self.host=(value)
      @@host = value
    end

    def self.password      
      @@password
    end

    def self.password=(value)
      @@password = value
    end



  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rjobs-0.3.3.alpha lib/rjobs/job_handler.rb
rjobs-0.3.2.alpha lib/rjobs/job_handler.rb