class BatchKit::Database::Job
Records details of job definitions
Public Class Methods
new(job_def, md5)
click to toggle source
Calls superclass method
# File lib/batch-kit/database/models.rb, line 112 def initialize(job_def, md5) log.detail "Registering job '#{job_def.name}' on #{job_def.computer} in batch database" super(job_name: job_def.name, job_class: job_def.job_class.name, job_method: job_def.method_name, job_desc: job_def.description, job_host: job_def.computer, job_file: job_def.file, job_version: md5.object_version, md5: md5, job_run_count: 0, job_success_count: 0, job_fail_count: 0, job_abort_count: 0, job_min_success_duration_ms: 0, job_max_success_duration_ms: 0, job_mean_success_duration_ms: 0, job_m2_success_duration_ms: 0) end
register(job_def)
click to toggle source
Ensures that the job described by job_def
has been registered in the batch database.
# File lib/batch-kit/database/models.rb, line 84 def self.register(job_def) job = self.where(job_class: job_def.job_class.name, job_host: job_def.computer).first job_file = IO.read(job_def.file) ok, md5 = MD5.check('JOB', "//#{job_def.computer}/#{job_def.file}", job_file) md5.save unless ok if job # Existing job unless ok == job.job_file_md5_id job.update(job_name: job_def.name, job_method: job_def.method_name, job_desc: job_def.description, job_file: job_def.file, job_version: md5.object_version, md5: md5) end else # New job job = self.new(job_def, md5).save end job_def.job_id = job.job_id job_def.job_version = job.job_version job end
Public Instance Methods
job_abort(job_run)
click to toggle source
job_failure(job_run)
click to toggle source
job_start(job_run)
click to toggle source
Record the start of a job run
@param job_run [JobRun] The JobRun
instance that has commenced.
# File lib/batch-kit/database/models.rb, line 128 def job_start(job_run) self.job_last_run_at = job_run.start_time self.job_run_count += 1 self.save end
job_success(job_run)
click to toggle source
Record the successful completion of the JobRun
.
@param job_run [JobRun] The JobRun
instance that has completed.
# File lib/batch-kit/database/models.rb, line 138 def job_success(job_run) self.job_success_count += 1 n = self.job_success_count ms = job_run.elapsed * 1000 delta = ms - self.job_mean_success_duration_ms self.job_min_success_duration_ms = self.job_min_success_duration_ms == 0 ? ms : [self.job_min_success_duration_ms, ms].min self.job_max_success_duration_ms = self.job_max_success_duration_ms == 0 ? ms : [self.job_max_success_duration_ms, ms].max mean = self.job_mean_success_duration_ms += delta / n self.job_m2_success_duration_ms += delta * (ms - mean) self.save end
job_timeout(job_run)
click to toggle source
Record that a JobRun
has timed out. This happens when the database finds an instance in the table that has been running for a long period without any activity.
@param job_run [JobRun] The JobRun
instance that has aborted.
# File lib/batch-kit/database/models.rb, line 176 def job_timeout(job_run) self.job_abort_count += 1 self.save end
log()
click to toggle source
# File lib/batch-kit/database/models.rb, line 107 def log @log ||= LogManager.logger('batch-kit.job') end