Skip to content

Instantly share code, notes, and snippets.

@thedayisntgray
Last active October 4, 2024 16:03
Show Gist options
  • Save thedayisntgray/2f13cdfcd1fe9e4533fb4d676bef62d4 to your computer and use it in GitHub Desktop.
Save thedayisntgray/2f13cdfcd1fe9e4533fb4d676bef62d4 to your computer and use it in GitHub Desktop.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
workflow_config = WorkflowConfig.new
workflow_config.on_success = -> { email_result(true, "Workflow completed successfully!") }
workflow_config.on_failure = ->(error) { email_result(false, "Workflow failed: #{error}") }
# Task 1: Data Preparation
workflow_config.add_task(TaskConfig.new(
name: "data_preparation",
agent: "DataProcessing::PrepAgent",
max_retries: 3,
on_success: -> { notify_success("Data Preparation") },
on_failure: ->(error) { notify_failure("Data Preparation", error) }
))
# Task 2: Data Analysis
workflow_config.add_task(TaskConfig.new(
name: "data_analysis",
agent: -> { puts "Performing data analysis..." },
seed: { algorithm: "random_forest", parameters: { trees: 100, depth: 10 } },
on_success: -> { notify_success("Data Analysis") },
on_failure: ->(error) { notify_failure("Data Analysis", error) }
))
# Task 3: Report Generation
workflow_config.add_task(TaskConfig.new(
name: "report_generation",
agent: "Reporting::PDFGenerator",
seed: { template: "quarterly_report", data_source: "analysis_results" },
on_success: -> { notify_success("Report Generation") },
on_failure: ->(error) { notify_failure("Report Generation", error) }
))
# Completion Step
workflow_config.set_completion_step(TaskConfig.new(
name: "completion",
agent: -> {
puts "Finalizing workflow..."
SecureRandom.uuid # Generate a unique ID for this workflow run
},
max_retries: 1,
on_success: -> { puts "Workflow completion step succeeded!" },
on_failure: ->(error) { puts "Workflow completion step failed: #{error}" }
))
# Example of how to access the configuration
puts "Workflow Tasks:"
workflow_config.tasks.each do |name, task|
puts "- #{name} (Max retries: #{task.max_retries})"
end
puts "Completion Step: #{workflow_config.completion_step.name}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment