Class: Fractor::Workflow::ExecutionTrace
- Inherits:
-
Object
- Object
- Fractor::Workflow::ExecutionTrace
- Defined in:
- lib/fractor/workflow/execution_trace.rb
Overview
Tracks execution details for workflow runs. Provides detailed trace of job execution, timings, and results.
Defined Under Namespace
Classes: JobTrace
Instance Attribute Summary collapse
-
#completed_at ⇒ Object
readonly
Returns the value of attribute completed_at.
-
#correlation_id ⇒ Object
readonly
Returns the value of attribute correlation_id.
-
#execution_id ⇒ Object
readonly
Returns the value of attribute execution_id.
-
#job_traces ⇒ Object
readonly
Returns the value of attribute job_traces.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
-
#workflow_name ⇒ Object
readonly
Returns the value of attribute workflow_name.
Instance Method Summary collapse
-
#complete! ⇒ Object
Mark the workflow as completed.
-
#initialize(workflow_name:, execution_id:, correlation_id:) ⇒ ExecutionTrace
constructor
A new instance of ExecutionTrace.
-
#start_job(job_name:, worker_class:) ⇒ Object
Record the start of a job execution.
-
#to_h ⇒ Object
Convert trace to hash for serialization.
-
#to_json(*_args) ⇒ Object
Convert trace to JSON.
-
#total_duration_ms ⇒ Object
Total duration in milliseconds.
Constructor Details
#initialize(workflow_name:, execution_id:, correlation_id:) ⇒ ExecutionTrace
Returns a new instance of ExecutionTrace.
13 14 15 16 17 18 19 20 |
# File 'lib/fractor/workflow/execution_trace.rb', line 13 def initialize(workflow_name:, execution_id:, correlation_id:) @workflow_name = workflow_name @execution_id = execution_id @correlation_id = correlation_id @started_at = Time.now.utc @completed_at = nil @job_traces = [] end |
Instance Attribute Details
#completed_at ⇒ Object (readonly)
Returns the value of attribute completed_at.
10 11 12 |
# File 'lib/fractor/workflow/execution_trace.rb', line 10 def completed_at @completed_at end |
#correlation_id ⇒ Object (readonly)
Returns the value of attribute correlation_id.
10 11 12 |
# File 'lib/fractor/workflow/execution_trace.rb', line 10 def correlation_id @correlation_id end |
#execution_id ⇒ Object (readonly)
Returns the value of attribute execution_id.
10 11 12 |
# File 'lib/fractor/workflow/execution_trace.rb', line 10 def execution_id @execution_id end |
#job_traces ⇒ Object (readonly)
Returns the value of attribute job_traces.
10 11 12 |
# File 'lib/fractor/workflow/execution_trace.rb', line 10 def job_traces @job_traces end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
10 11 12 |
# File 'lib/fractor/workflow/execution_trace.rb', line 10 def started_at @started_at end |
#workflow_name ⇒ Object (readonly)
Returns the value of attribute workflow_name.
10 11 12 |
# File 'lib/fractor/workflow/execution_trace.rb', line 10 def workflow_name @workflow_name end |
Instance Method Details
#complete! ⇒ Object
Mark the workflow as completed
33 34 35 |
# File 'lib/fractor/workflow/execution_trace.rb', line 33 def complete! @completed_at = Time.now.utc end |
#start_job(job_name:, worker_class:) ⇒ Object
Record the start of a job execution
23 24 25 26 27 28 29 30 |
# File 'lib/fractor/workflow/execution_trace.rb', line 23 def start_job(job_name:, worker_class:) job_trace = JobTrace.new( job_name: job_name, worker_class: worker_class, ) @job_traces << job_trace job_trace end |
#to_h ⇒ Object
Convert trace to hash for serialization
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fractor/workflow/execution_trace.rb', line 45 def to_h { workflow: @workflow_name, execution_id: @execution_id, correlation_id: @correlation_id, started_at: @started_at.strftime("%Y-%m-%dT%H:%M:%S.%3NZ"), completed_at: @completed_at&.strftime("%Y-%m-%dT%H:%M:%S.%3NZ"), total_duration_ms: total_duration_ms, jobs: @job_traces.map(&:to_h), } end |
#to_json(*_args) ⇒ Object
Convert trace to JSON
58 59 60 |
# File 'lib/fractor/workflow/execution_trace.rb', line 58 def to_json(*_args) to_h.to_json end |
#total_duration_ms ⇒ Object
Total duration in milliseconds
38 39 40 41 42 |
# File 'lib/fractor/workflow/execution_trace.rb', line 38 def total_duration_ms return nil unless @completed_at ((@completed_at - @started_at) * 1000).round(2) end |