Class: Torque::JobLog

Inherits:
Object
  • Object
show all
Defined in:
lib/bookie/senders/torque_cluster.rb

Overview

Represents a job record file

Defined Under Namespace

Classes: InvalidLineError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ JobLog

Creates a JobRecord using the TORQUE record file for the given date



62
63
64
65
# File 'lib/bookie/senders/torque_cluster.rb', line 62

def initialize(filename)
  @filename = filename
  @file = File.open(filename)
end

Instance Attribute Details

#filenameObject (readonly)

The name of the accounting file opened



59
60
61
# File 'lib/bookie/senders/torque_cluster.rb', line 59

def filename
  @filename
end

Class Method Details

.filename_for_date(date) ⇒ Object

Converts a date to the name of the file holding entries for that date



149
150
151
# File 'lib/bookie/senders/torque_cluster.rb', line 149

def self.filename_for_date(date)
  File.join(Torque::torque_root, 'server_priv', 'accounting', date.strftime("%Y%m%d"))
end

Instance Method Details

#each_jobObject

Yields each completed job to the given block



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/bookie/senders/torque_cluster.rb', line 77

def each_job
  @file.rewind
  line_num = 0
  @file.each_line do |line|
    line_num += 1
    next if line.strip! == ''
    #Skip the timestamp.
    index = line.index(';')
    raise invalid_line_error(line_num) unless index
    
    #Find the event type.
    event_type = line[index + 1]
    old_index = index
    index = line.index(';', index + 1)
    raise invalid_line_error(line_num) unless index == old_index + 2
    next unless event_type == ?E
    
    #Find the fields.
    index = line.index(';', index + 1)
    raise invalid_line_error(line_num) unless index
    fields = line[index + 1 .. -1].split(' ')
    
    job = Job.new()
    
    #To consider: make sure all fields are present?
    fields.each do |field|
      key, value = *field.split('=')
      case key
        when "user"
          job.user_name = value
        when "group"
          job.group_name = value
        when "start"
          job.start_time = Time.at(Integer(value))
        when "resources_used.walltime"
          job.wall_time = parse_duration(value)
        when "resources_used.cput"
          job.cpu_time = parse_duration(value)
        when "resources_used.mem"
          job.physical_memory = Integer(value[0 ... -2])
        when "resources_used.vmem"
          job.virtual_memory = Integer(value[0 ... -2])
        when "Exit_status"
          job.exit_code = Integer(value)
      end
    end
    job.command_name = ""
    
    yield job
  end
end