mirror of
https://github.com/plashchynski/crono.git
synced 2026-03-24 02:11:39 +01:00
Add Job#healthy
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user