|
| 1 | +# Flow Chaining Example |
| 2 | + |
| 3 | +Minimal example showing how to chain flows using `@trigger_on_finish`. |
| 4 | + |
| 5 | +## Structure |
| 6 | + |
| 7 | +``` |
| 8 | +flow-chaining-example/ |
| 9 | + obproject.toml |
| 10 | + flows/ |
| 11 | + preprocess/flow.py # Runs first, processes datasets in parallel |
| 12 | + train/flow.py # Triggered when preprocess finishes |
| 13 | +``` |
| 14 | + |
| 15 | +## How It Works |
| 16 | + |
| 17 | +1. **PreprocessFlow** runs with a `datasets` parameter (comma-separated paths) |
| 18 | +2. Uses `foreach` to process each dataset in parallel |
| 19 | +3. Stores results in `self.processed_paths` artifact |
| 20 | +4. **TrainFlow** has `@trigger_on_finish(flow="PreprocessFlow")` |
| 21 | +5. When PreprocessFlow completes, TrainFlow starts automatically |
| 22 | +6. TrainFlow accesses data via `current.trigger.run.data.processed_paths` |
| 23 | + |
| 24 | +## Testing Locally |
| 25 | + |
| 26 | +```bash |
| 27 | +# Test PreprocessFlow standalone |
| 28 | +cd flows/preprocess |
| 29 | +python flow.py run --datasets "path1,path2,path3" |
| 30 | + |
| 31 | +# Test TrainFlow standalone (without trigger) |
| 32 | +cd flows/train |
| 33 | +python flow.py run --learning_rate 0.05 --n_estimators 200 |
| 34 | +``` |
| 35 | + |
| 36 | +## Deploy to Outerbounds |
| 37 | + |
| 38 | +```bash |
| 39 | +obproject-deploy |
| 40 | +``` |
| 41 | + |
| 42 | +After deploy: |
| 43 | +1. Run PreprocessFlow from UI or CLI |
| 44 | +2. TrainFlow will trigger automatically when it finishes |
| 45 | +3. TrainFlow parameters (learning_rate, n_estimators) use deploy-time defaults |
| 46 | + |
| 47 | +## Passing Parameters at Runtime |
| 48 | + |
| 49 | +TrainFlow parameters are set at **deploy time** via the flow definition defaults. |
| 50 | +To change them per-run, either: |
| 51 | + |
| 52 | +1. **Redeploy** with different defaults |
| 53 | +2. **Use artifacts** instead of Parameters for runtime values: |
| 54 | + - PreprocessFlow stores config in an artifact |
| 55 | + - TrainFlow reads it via `current.trigger.run.data.config` |
| 56 | + |
| 57 | +## Key Pattern |
| 58 | + |
| 59 | +```python |
| 60 | +# In TrainFlow |
| 61 | +@trigger_on_finish(flow="PreprocessFlow") |
| 62 | +class TrainFlow(ProjectFlow): |
| 63 | + |
| 64 | + @step |
| 65 | + def start(self): |
| 66 | + if current.trigger: |
| 67 | + # Access parent flow's artifacts |
| 68 | + data = current.trigger.run.data.processed_paths |
| 69 | +``` |
0 commit comments