Class: DurableFlow::WorkflowTimeline
- Inherits:
-
Object
- Object
- DurableFlow::WorkflowTimeline
- Defined in:
- lib/durable_flow/workflow_timeline.rb
Defined Under Namespace
Constant Summary collapse
- ITEM_TYPE_ORDER =
{ step: 0, wait: 1, event: 2, log: 3, }.freeze
Instance Attribute Summary collapse
-
#workflow_run ⇒ Object
readonly
Returns the value of attribute workflow_run.
Instance Method Summary collapse
- #events ⇒ Object
-
#initialize(workflow_run) ⇒ WorkflowTimeline
constructor
A new instance of WorkflowTimeline.
- #items ⇒ Object
- #logs ⇒ Object
- #logs_for(step_or_id) ⇒ Object
- #run_logs ⇒ Object
- #step_entries ⇒ Object
- #step_entry_for(step_or_id) ⇒ Object
- #steps ⇒ Object
- #waits ⇒ Object
- #waits_for(step_or_id) ⇒ Object
Constructor Details
#initialize(workflow_run) ⇒ WorkflowTimeline
Returns a new instance of WorkflowTimeline.
59 60 61 |
# File 'lib/durable_flow/workflow_timeline.rb', line 59 def initialize(workflow_run) @workflow_run = workflow_run end |
Instance Attribute Details
#workflow_run ⇒ Object (readonly)
Returns the value of attribute workflow_run.
57 58 59 |
# File 'lib/durable_flow/workflow_timeline.rb', line 57 def workflow_run @workflow_run end |
Instance Method Details
#events ⇒ Object
92 93 94 |
# File 'lib/durable_flow/workflow_timeline.rb', line 92 def events @events ||= waits.filter_map(&:workflow_event).uniq end |
#items ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/durable_flow/workflow_timeline.rb', line 108 def items @items ||= [ steps.map { |step| item_for_step(step) }, waits.map { |wait| item_for_wait(wait) }, events.map { |event| item_for_event(event) }, logs.map { |log| item_for_log(log) }, ].flatten.sort_by { |item| item_sort_key(item) } end |
#logs ⇒ Object
88 89 90 |
# File 'lib/durable_flow/workflow_timeline.rb', line 88 def logs @logs ||= workflow_run.workflow_logs.includes(:workflow_step).ordered.to_a end |
#logs_for(step_or_id) ⇒ Object
100 101 102 |
# File 'lib/durable_flow/workflow_timeline.rb', line 100 def logs_for(step_or_id) logs_by_step_id.fetch(record_id(step_or_id), []) end |
#run_logs ⇒ Object
96 97 98 |
# File 'lib/durable_flow/workflow_timeline.rb', line 96 def run_logs @run_logs ||= logs.reject(&:workflow_step_id) end |
#step_entries ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/durable_flow/workflow_timeline.rb', line 63 def step_entries @step_entries ||= steps.map do |step| waits = waits_for(step) StepEntry.new( step: step, logs: logs_for(step), waits: waits, events: waits.filter_map(&:workflow_event), ) end end |
#step_entry_for(step_or_id) ⇒ Object
76 77 78 |
# File 'lib/durable_flow/workflow_timeline.rb', line 76 def step_entry_for(step_or_id) step_entries.find { |entry| entry.id == record_id(step_or_id) } end |
#steps ⇒ Object
80 81 82 |
# File 'lib/durable_flow/workflow_timeline.rb', line 80 def steps @steps ||= workflow_run.workflow_steps.order(:created_at, :id).to_a end |
#waits ⇒ Object
84 85 86 |
# File 'lib/durable_flow/workflow_timeline.rb', line 84 def waits @waits ||= workflow_run.workflow_waits.includes(:workflow_event).order(:created_at, :id).to_a end |
#waits_for(step_or_id) ⇒ Object
104 105 106 |
# File 'lib/durable_flow/workflow_timeline.rb', line 104 def waits_for(step_or_id) waits_by_step_id.fetch(record_id(step_or_id), []) end |