Class: Fractor::Workflow::ExecutionTrace::JobTrace
- Inherits:
-
Object
- Object
- Fractor::Workflow::ExecutionTrace::JobTrace
- Defined in:
- lib/fractor/workflow/execution_trace.rb
Overview
Trace data for a single job execution
Instance Attribute Summary collapse
-
#completed_at ⇒ Object
readonly
Returns the value of attribute completed_at.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#job_name ⇒ Object
readonly
Returns the value of attribute job_name.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#worker_class ⇒ Object
readonly
Returns the value of attribute worker_class.
Instance Method Summary collapse
-
#complete!(output: nil) ⇒ Object
Mark job as successfully completed.
-
#duration_ms ⇒ Object
Duration in milliseconds.
-
#fail!(error:) ⇒ Object
Mark job as failed.
-
#initialize(job_name:, worker_class:) ⇒ JobTrace
constructor
A new instance of JobTrace.
-
#set_input(input) ⇒ Object
Set input hash for tracking.
-
#to_h ⇒ Object
Convert to hash for serialization.
Constructor Details
#initialize(job_name:, worker_class:) ⇒ JobTrace
Returns a new instance of JobTrace.
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/fractor/workflow/execution_trace.rb', line 67 def initialize(job_name:, worker_class:) @job_name = job_name @worker_class = worker_class @started_at = Time.now.utc @completed_at = nil @status = :running @error = nil @input_hash = nil @output_hash = nil end |
Instance Attribute Details
#completed_at ⇒ Object (readonly)
Returns the value of attribute completed_at.
64 65 66 |
# File 'lib/fractor/workflow/execution_trace.rb', line 64 def completed_at @completed_at end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
64 65 66 |
# File 'lib/fractor/workflow/execution_trace.rb', line 64 def error @error end |
#job_name ⇒ Object (readonly)
Returns the value of attribute job_name.
64 65 66 |
# File 'lib/fractor/workflow/execution_trace.rb', line 64 def job_name @job_name end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
64 65 66 |
# File 'lib/fractor/workflow/execution_trace.rb', line 64 def started_at @started_at end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
64 65 66 |
# File 'lib/fractor/workflow/execution_trace.rb', line 64 def status @status end |
#worker_class ⇒ Object (readonly)
Returns the value of attribute worker_class.
64 65 66 |
# File 'lib/fractor/workflow/execution_trace.rb', line 64 def worker_class @worker_class end |
Instance Method Details
#complete!(output: nil) ⇒ Object
Mark job as successfully completed
79 80 81 82 83 |
# File 'lib/fractor/workflow/execution_trace.rb', line 79 def complete!(output: nil) @completed_at = Time.now.utc @status = :success @output_hash = hash_value(output) if output end |
#duration_ms ⇒ Object
Duration in milliseconds
102 103 104 105 106 |
# File 'lib/fractor/workflow/execution_trace.rb', line 102 def duration_ms return nil unless @completed_at ((@completed_at - @started_at) * 1000).round(2) end |
#fail!(error:) ⇒ Object
Mark job as failed
86 87 88 89 90 91 92 93 94 |
# File 'lib/fractor/workflow/execution_trace.rb', line 86 def fail!(error:) @completed_at = Time.now.utc @status = :failed @error = { class: error.class.name, message: error., backtrace: error.backtrace&.first(5), } end |
#set_input(input) ⇒ Object
Set input hash for tracking
97 98 99 |
# File 'lib/fractor/workflow/execution_trace.rb', line 97 def set_input(input) @input_hash = hash_value(input) end |
#to_h ⇒ Object
Convert to hash for serialization
109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/fractor/workflow/execution_trace.rb', line 109 def to_h { name: @job_name, worker: @worker_class, started_at: @started_at.strftime("%Y-%m-%dT%H:%M:%S.%3NZ"), completed_at: @completed_at&.strftime("%Y-%m-%dT%H:%M:%S.%3NZ"), duration_ms: duration_ms, status: @status.to_s, input_hash: @input_hash, output_hash: @output_hash, error: @error, }.compact end |