Class: ProcessLog
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- ProcessLog
- Defined in:
- app/models/process_log.rb
Instance Method Summary collapse
-
#completed? ⇒ Boolean
Methods.
- #elapsed ⇒ Object
-
#fail!(exception = nil, comment: nil, backtrace: nil) ⇒ Object
Fail the Process Log.
- #fail? ⇒ Boolean
- #local_end ⇒ Object
- #local_start ⇒ Object
- #progress ⇒ Object
- #siblings ⇒ Object
- #started? ⇒ Boolean
- #status ⇒ Object
- #success! ⇒ Object
- #success? ⇒ Boolean
- #to_s ⇒ Object
Instance Method Details
#completed? ⇒ Boolean
Methods
20 21 22 |
# File 'app/models/process_log.rb', line 20 def completed? !!elapsed end |
#elapsed ⇒ Object
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
49 50 51 |
# File 'app/models/process_log.rb', line 49 def fail? status == "Fail" end |
#local_end ⇒ Object
53 54 55 |
# File 'app/models/process_log.rb', line 53 def local_end end_time&.localtime&.strftime("%F %-l:%M%P") end |
#local_start ⇒ Object
57 58 59 |
# File 'app/models/process_log.rb', line 57 def local_start start_time&.localtime&.strftime("%F %-l:%M%P") end |
#progress ⇒ Object
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 |
#siblings ⇒ Object
65 66 67 |
# File 'app/models/process_log.rb', line 65 def siblings ProcessLog.where(key: key) end |
#started? ⇒ Boolean
69 70 71 |
# File 'app/models/process_log.rb', line 69 def started? status == "Started" end |
#status ⇒ Object
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
83 84 85 |
# File 'app/models/process_log.rb', line 83 def success? status == "Success" end |
#to_s ⇒ Object
87 88 89 |
# File 'app/models/process_log.rb', line 87 def to_s key end |