Class: ProcessLog

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/process_log.rb

Instance Method Summary collapse

Instance Method Details

#completed?Boolean

Methods

Returns:

  • (Boolean)


20
21
22
# File 'app/models/process_log.rb', line 20

def completed?
  !!elapsed
end

#elapsedObject



24
25
26
# File 'app/models/process_log.rb', line 24

def elapsed
  super || [(Time.now - start_time).to_i, 86400].min
end

#fail!(exception = nil, comment: nil, backtrace: nil) ⇒ Object

Fail the Process Log. Pass in nothing for no comment or backtrace Pass in the Exception itself to automatically extract. Pass in comment and/or backtrace to set/overwrite.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/process_log.rb', line 32

def fail!(exception = nil, comment: nil, backtrace: nil)
  self.status = "Fail"
  self.end_time = Time.now

  unless exception.blank?
    self.comment = exception.to_s
    self.backtrace = exception.backtrace.join("\n")
  end

  # Manually passed named arguments overwrite exception if that was also provided.
  self.comment    = comment unless comment.blank?
  self.comment  ||= 'Fail'
  self.backtrace  = Array(backtrace).join("\n") unless backtrace.blank?

  save
end

#fail?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'app/models/process_log.rb', line 49

def fail?
  status == "Fail"
end

#local_endObject



53
54
55
# File 'app/models/process_log.rb', line 53

def local_end
  end_time&.localtime&.strftime("%F %-l:%M%P")
end

#local_startObject



57
58
59
# File 'app/models/process_log.rb', line 57

def local_start
  start_time&.localtime&.strftime("%F %-l:%M%P")
end

#progressObject



61
62
63
# File 'app/models/process_log.rb', line 61

def progress
  success? ? 100 : [99, (100 * elapsed / average_elapsed).to_i].min rescue "?"
end

#siblingsObject



65
66
67
# File 'app/models/process_log.rb', line 65

def siblings
  ProcessLog.where(key: key)
end

#started?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'app/models/process_log.rb', line 69

def started?
  status == "Started"
end

#statusObject



73
74
75
# File 'app/models/process_log.rb', line 73

def status
  elapsed >= 86400 ? "Fail" : super
end

#success!Object



77
78
79
80
81
# File 'app/models/process_log.rb', line 77

def success!
  self.status = "Success" unless status == "Fail"
  self.end_time = Time.now
  save!
end

#success?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'app/models/process_log.rb', line 83

def success?
  status == "Success"
end

#to_sObject



87
88
89
# File 'app/models/process_log.rb', line 87

def to_s
  key
end