Class: Kuroko2::JobInstance
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Kuroko2::JobInstance
- Includes:
- TableNameCustomizable
- Defined in:
- app/models/kuroko2/job_instance.rb
Instance Attribute Summary collapse
-
#log_message ⇒ Object
Returns the value of attribute log_message.
Instance Method Summary collapse
- #cancel(by:) ⇒ Object
- #cancelable? ⇒ Boolean
- #error? ⇒ Boolean
- #execution_minutes ⇒ Object
-
#log_memory_consumption(value) ⇒ Object
Log given value if it is greater than stored one.
- #status ⇒ Object
- #working? ⇒ Boolean
Instance Attribute Details
#log_message ⇒ Object
Returns the value of attribute log_message.
6 7 8 |
# File 'app/models/kuroko2/job_instance.rb', line 6 def @log_message end |
Instance Method Details
#cancel(by:) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/models/kuroko2/job_instance.rb', line 49 def cancel(by:) self.tokens.destroy(*self.tokens) self.executions.destroy(*self.executions) self.touch(:canceled_at) = "This job was canceled by #{by}." self.logs.warn() Kuroko2.logger.warn() Kuroko2::Workflow::Notifier.notify(:cancellation, self) if job_definition.hipchat_notify_finished? end |
#cancelable? ⇒ Boolean
45 46 47 |
# File 'app/models/kuroko2/job_instance.rb', line 45 def cancelable? tokens.first.try(:cancelable?) end |
#error? ⇒ Boolean
37 38 39 |
# File 'app/models/kuroko2/job_instance.rb', line 37 def error? working? && error_at? end |
#execution_minutes ⇒ Object
74 75 76 |
# File 'app/models/kuroko2/job_instance.rb', line 74 def execution_minutes (((error_at || canceled_at || finished_at || Time.current) - created_at).to_f / 60).round(2) end |
#log_memory_consumption(value) ⇒ Object
Log given value if it is greater than stored one. This logging is not so important that we can ignore race condition, so we use ‘#update` and `#create_association` without bang here.
65 66 67 68 69 70 71 72 |
# File 'app/models/kuroko2/job_instance.rb', line 65 def log_memory_consumption(value) if memory_consumption_log max = [value, memory_consumption_log.value].max memory_consumption_log.update(value: max) else create_memory_consumption_log(value: value) end end |
#status ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/models/kuroko2/job_instance.rb', line 78 def status if finished_at? 'success' elsif canceled_at? 'canceled' elsif error_at? 'error' else 'working' end end |
#working? ⇒ Boolean
41 42 43 |
# File 'app/models/kuroko2/job_instance.rb', line 41 def working? !finished_at? && !canceled_at? end |