Class: Roast::Workflow::OutputHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/roast/workflow/output_handler.rb

Overview

Handles output operations for workflows including saving final output and results

Instance Method Summary collapse

Instance Method Details

#save_final_output(workflow) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/roast/workflow/output_handler.rb', line 7

def save_final_output(workflow)
  return unless workflow.respond_to?(:session_name) && workflow.session_name && workflow.respond_to?(:final_output)

  begin
    final_output = workflow.final_output.to_s
    return if final_output.empty?

    state_repository = StateRepositoryFactory.create(workflow.storage_type)
    output_file = state_repository.save_final_output(workflow, final_output)
    $stderr.puts "Final output saved to: #{output_file}" if output_file
  rescue => e
    # Don't fail if saving output fails
    $stderr.puts "Warning: Failed to save final output to session: #{e.message}"
  end
end

#write_results(workflow) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/roast/workflow/output_handler.rb', line 23

def write_results(workflow)
  if workflow.output_file
    File.write(workflow.output_file, workflow.final_output)
    $stdout.puts "Results saved to #{workflow.output_file}"
  else
    $stderr.puts "🔥🔥🔥 Final Output: 🔥🔥🔥"
    $stdout.puts workflow.final_output
  end
end