Class: HostStatistics

Inherits:
Object
  • Object
show all
Defined in:
lib/jobserver.rb

Overview

This class is used internally by the JobServer to collect statistics for each host.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHostStatistics

Returns a new instance of HostStatistics.



294
295
296
297
298
299
300
# File 'lib/jobserver.rb', line 294

def initialize
  @num_jobs_started = 0
  @num_jobs_finished = 0
  @num_jobs_failed = 0
  @userTime = 0.0
  @startTime = 0.0
end

Instance Attribute Details

#num_jobs_finishedObject

:nodoc:



293
294
295
# File 'lib/jobserver.rb', line 293

def num_jobs_finished
  @num_jobs_finished
end

Instance Method Details

#begin_updateObject

is called before a job is run



303
304
305
306
# File 'lib/jobserver.rb', line 303

def begin_update
  @startTime = Time.new
  @num_jobs_started += 1
end

#end_update(success) ⇒ Object

is called when a job has (successfully) terminated



309
310
311
312
313
314
315
316
# File 'lib/jobserver.rb', line 309

def end_update(success)
  @userTime += Time.new - @startTime
  if success
    @num_jobs_finished += 1
  else
    @num_jobs_failed += 1
  end
end

#to_sObject

returns the current statistics



319
320
321
322
323
324
325
326
327
# File 'lib/jobserver.rb', line 319

def to_s
  avgTime = @num_jobs_finished > 0 ? '%.1f s' % (@userTime / @num_jobs_finished) : '<no jobs finished>'
  s="Number of jobs finished: #{@num_jobs_finished}, average time per job: #{avgTime}"
  if (diff=(@num_jobs_started-@num_jobs_failed-@num_jobs_finished)) > 0
    s += ", #{diff} job#{(diff > 1) ? 's' : ''} running" 
  end
  s += ", #{@num_jobs_failed} job#{(@num_jobs_failed > 1) ? 's' : ''} failed" if @num_jobs_failed > 0
  s
end