Class: BatchKit::Database::Job
- Inherits:
-
Object
- Object
- BatchKit::Database::Job
- Defined in:
- lib/batch-kit/database/models.rb
Overview
Records details of job definitions
Class Method Summary collapse
-
.register(job_def) ⇒ Object
Ensures that the job described by
job_def
has been registered in the batch database.
Instance Method Summary collapse
-
#initialize(job_def, md5) ⇒ Job
constructor
A new instance of Job.
-
#job_abort(job_run) ⇒ Object
Record that a JobRun has been aborted.
-
#job_failure(job_run) ⇒ Object
Record the failure of a JobRun.
-
#job_start(job_run) ⇒ Object
Record the start of a job run.
-
#job_success(job_run) ⇒ Object
Record the successful completion of the JobRun.
-
#job_timeout(job_run) ⇒ Object
Record that a JobRun has timed out.
- #log ⇒ Object
Constructor Details
#initialize(job_def, md5) ⇒ Job
Returns a new instance of Job.
112 113 114 115 116 117 118 119 120 121 122 |
# 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 |
Class Method Details
.register(job_def) ⇒ Object
Ensures that the job described by job_def
has been registered in the batch database.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# 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 |
Instance Method Details
#job_abort(job_run) ⇒ Object
Record that a JobRun has been aborted.
165 166 167 168 |
# File 'lib/batch-kit/database/models.rb', line 165 def job_abort(job_run) self.job_abort_count += 1 self.save end |
#job_failure(job_run) ⇒ Object
Record the failure of a JobRun.
156 157 158 159 |
# File 'lib/batch-kit/database/models.rb', line 156 def job_failure(job_run) self.job_fail_count += 1 self.save end |
#job_start(job_run) ⇒ Object
Record the start of a job run
128 129 130 131 132 |
# 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) ⇒ Object
Record the successful completion of the JobRun.
138 139 140 141 142 143 144 145 146 147 148 149 150 |
# 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) ⇒ Object
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.
176 177 178 179 |
# File 'lib/batch-kit/database/models.rb', line 176 def job_timeout(job_run) self.job_abort_count += 1 self.save end |
#log ⇒ Object
107 108 109 |
# File 'lib/batch-kit/database/models.rb', line 107 def log @log ||= LogManager.logger('batch-kit.job') end |