Add Job#healthy

This commit is contained in:
Dzmitry Plashchynski
2015-03-10 00:19:33 +02:00
parent 54a1b53af9
commit a24389f6cc
4 changed files with 20 additions and 3 deletions

View File

@@ -10,6 +10,7 @@ module Crono
attr_accessor :last_performed_at
attr_accessor :job_log
attr_accessor :job_logger
attr_accessor :healthy
def initialize(performer, period)
self.performer, self.period = performer, period
@@ -41,7 +42,9 @@ module Crono
rescue Exception => e
log "Finished #{performer} in %.2f seconds with error: #{e.message}" % (Time.now - last_performed_at)
log e.backtrace.join("\n")
self.healthy = false
else
self.healthy = true
log "Finished #{performer} in %.2f seconds" % (Time.now - last_performed_at)
ensure
save
@@ -54,7 +57,7 @@ module Crono
log = model.reload.log || ""
log << job_log.string
job_log.truncate(job_log.rewind)
model.update(last_performed_at: last_performed_at, log: log)
model.update(last_performed_at: last_performed_at, log: log, healthy: healthy)
end
end

View File

@@ -4,6 +4,7 @@ class CreateCronoJobs < ActiveRecord::Migration
t.string :job_id, null: false
t.text :log
t.datetime :last_performed_at
t.boolean :healthy
t.timestamps null: false
end
add_index :crono_jobs, [:job_id], unique: true