Discover Packages
github.com/dracory/base
wf
examples
dag_conditional_logic
command
Version:
v0.18.0
Opens a new window with list of versions in this module.
Published: May 8, 2025
License: AGPL-3.0
Opens a new window with license information.
Imports: 4
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
README
¶
Conditional Logic Example
This example demonstrates how to implement conditional logic using DAGs and pipelines in the Dracory steps package. It shows two approaches to handling different order types (digital, physical, subscription) with varying processing requirements.
Key Features
DAG Implementation:
Uses dependencies to maintain step ordering
Conditionally adds steps based on order type
Maintains proper execution flow through dependencies
Pipeline Implementation:
Groups related steps into logical pipelines
Simplifies conditional logic by adding steps to pipelines
Maintains proper execution order within pipelines
Reduces code duplication
Order Types and Processing
Digital Orders
ProcessOrder → ApplyDiscount → CalculateTax
No shipping cost
10% discount applied
20% tax applied
Physical Orders
ProcessOrder → ApplyDiscount → AddShipping → CalculateTax
Fixed $5 shipping cost
10% discount applied
20% tax applied
Subscription Orders
ProcessOrder → ApplyDiscount → CalculateTax
No shipping cost
10% discount applied
20% tax applied
Running the Example
To run this example:
# Run the tests
# Tests both DAG and pipeline implementations
go test -v
# Run the main program
# Demonstrates both implementations
go run main.go
Implementation Details
DAG Implementation
Uses direct dependencies between steps
Requires careful dependency management
More verbose for complex conditional logic
Pipeline Implementation
Groups related steps into pipelines
Simplifies conditional logic
More maintainable for complex scenarios
Easier to modify step order within pipelines
Example Output
When running main.go, you'll see:
Results from the DAG implementation
Results from the pipeline implementation
Both should produce identical results for each order type
Expand ▾
Collapse ▴
Documentation
¶
There is no documentation for this package.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.