Workflow Advanced Features
This guide covers advanced workflow features in Merobox, including parallel step execution and custom scripts.
Parallel Step Execution
Execute multiple steps simultaneously for improved performance:
Basic Parallel Execution
steps:
- name: Parallel Operations
type: parallel
steps:
- name: Install App 1
type: install_application
node: calimero-node-1
path: ./app1.wasm
dev: true
outputs:
app_id_1: applicationId
- name: Install App 2
type: install_application
node: calimero-node-2
path: ./app2.wasm
dev: true
outputs:
app_id_2: applicationId
- name: Create Identity
type: create_identity
node: calimero-node-3
outputs:
public_key: publicKey
Parallel with Repeat
steps:
- name: Parallel Repeat Operations
type: parallel
steps:
- name: Install Multiple Apps
type: repeat
count: 3
outputs:
iteration: iteration
steps:
- name: Install App {{iteration}}
type: install_application
node: calimero-node-{{iteration}}
path: ./app{{iteration}}.wasm
dev: true
outputs:
app_id: applicationId
Custom Scripts
Use custom scripts for complex operations:
Basic Script Execution
steps:
- name: Custom Setup Script
type: script
script: |
echo "Setting up custom environment..."
mkdir -p /tmp/custom-data
echo "custom_value" > /tmp/custom-data/sample.txt
echo "Setup complete"
outputs:
setup_result: output
- name: Use Script Output
type: call
node: calimero-node-1
context_id: '{{context_id}}'
method: process_data
args:
data: '{{setup_result}}'
Script with Variables
steps:
- name: Process Data Script
type: script
script: |
echo "Processing data for context: {{context_id}}"
echo "Using public key: {{public_key}}"
# Process the data
echo "processed_data" > /tmp/result.txt
echo "Processing complete"
outputs:
processed_data: output
Error Handling
Implement basic error handling in workflows:
Try-Catch Pattern
steps:
- name: Risky Operation
type: call
node: calimero-node-1
context_id: '{{context_id}}'
method: risky_method
args:
should_fail: false
outputs:
result: result
- name: Handle Success
type: script
script: |
echo "Operation succeeded: {{result}}"
condition: '{{result}} != null'
- name: Handle Error
type: script
script: |
echo "Operation failed, continuing..."
condition: '{{result}} == null'
Validation Steps
steps:
- name: Validate Input
type: assert
statements:
- 'is_set({{context_id}})'
- 'is_set({{public_key}})'
- name: Execute Operation
type: call
node: calimero-node-1
context_id: '{{context_id}}'
method: safe_method
args:
key: '{{public_key}}'
Performance Optimization
Resource Management
# Use appropriate node counts
nodes:
count: 3 # Scale based on needs
image: ghcr.io/calimero-network/merod:edge
steps:
- name: Efficient Operations
type: parallel
max_concurrent: 2 # Limit concurrent operations
steps:
- name: Operation 1
type: call
# ... operation details
- name: Operation 2
type: call
# ... operation details
Caching and Reuse
steps:
- name: Create Reusable Data
type: script
script: |
echo "Creating reusable data..."
echo "shared_data" > /tmp/shared.txt
outputs:
shared_data: output
- name: Use Shared Data
type: call
node: calimero-node-1
method: use_shared_data
args:
data: '{{shared_data}}'
- name: Use Shared Data Again
type: call
node: calimero-node-2
method: use_shared_data
args:
data: '{{shared_data}}'
Best Practices
1. Use Parallel Execution
# Good: Use parallel execution for independent operations
steps:
- name: Parallel Setup
type: parallel
steps:
- name: Setup Node 1
type: install_application
# ... setup details
- name: Setup Node 2
type: install_application
# ... setup details
2. Implement Error Handling
# Good: Include error handling
steps:
- name: Validate Before Execution
type: assert
statements:
- 'is_set({{required_variable}})'
- name: Execute Operation
type: call
# ... operation details
3. Use Appropriate Resources
# Good: Scale resources appropriately
nodes:
count: 3 # Use appropriate number of nodes
image: ghcr.io/calimero-network/merod:edge
Troubleshooting
Common Issues
Parallel Execution Failures
# Check node health
merobox health --verbose
# Check logs
merobox logs calimero-node-1
Script Execution Errors
# Run with verbose output
merobox bootstrap run workflow.yml --verbose
# Check script output
merobox logs calimero-node-1 | grep "script"
Next Steps
Now that you understand advanced workflow features:
- Best Practices - Guidelines for effective Merobox usage
- Troubleshooting - Common issues and solutions
Was this page helpful?