19 lines
514 B
Ruby
19 lines
514 B
Ruby
class JobLog < ApplicationRecord
|
|
belongs_to :server, optional: true
|
|
|
|
enum :status, { pending: 0, running: 1, completed: 2, failed: 3 }
|
|
|
|
scope :recent, -> { order(created_at: :desc) }
|
|
scope :for_server, ->(server_id) { where(server_id: server_id) }
|
|
|
|
def duration
|
|
return nil unless started_at && finished_at
|
|
finished_at - started_at
|
|
end
|
|
|
|
def append_log(message)
|
|
self.log_output ||= ""
|
|
self.log_output += "[#{Time.current.strftime('%Y-%m-%d %H:%M:%S')}] #{message}\n"
|
|
save
|
|
end
|
|
end
|