|
1 | 1 | --- |
2 | | -sidebar_position: 3 |
| 2 | +sidebar_position: 4 |
3 | 3 | --- |
4 | 4 |
|
5 | 5 | import Tabs from '@theme/Tabs'; |
@@ -28,58 +28,105 @@ uv add graflow |
28 | 28 | </TabItem> |
29 | 29 | </Tabs> |
30 | 30 |
|
31 | | -## Create a Workflow File |
| 31 | +## Your First Task |
32 | 32 |
|
33 | | -Create a new file called `workflow.yaml`: |
| 33 | +Create a file called `hello.py`: |
34 | 34 |
|
35 | | -```yaml |
36 | | -name: hello-world |
37 | | -description: My first Graflow workflow |
| 35 | +```python |
| 36 | +from graflow import task |
38 | 37 |
|
39 | | -tasks: |
40 | | - - name: greet |
41 | | - script: | |
42 | | - echo "Hello, Graflow!" |
43 | | -``` |
| 38 | +@task |
| 39 | +def hello(): |
| 40 | + print("Hello, Graflow!") |
| 41 | + return "success" |
44 | 42 |
|
45 | | -## Run the Workflow |
| 43 | +if __name__ == "__main__": |
| 44 | + result = hello.run() |
| 45 | + print(f"Task completed with result: {result}") |
| 46 | +``` |
46 | 47 |
|
47 | | -Execute your workflow using the Graflow CLI: |
| 48 | +Run it: |
48 | 49 |
|
49 | 50 | <Tabs> |
50 | 51 | <TabItem value="pip" label="pip" default> |
51 | 52 |
|
52 | 53 | ```bash |
53 | | -graflow run workflow.yaml |
| 54 | +python hello.py |
54 | 55 | ``` |
55 | 56 |
|
56 | 57 | </TabItem> |
57 | 58 | <TabItem value="uv" label="uv"> |
58 | 59 |
|
59 | 60 | ```bash |
60 | | -uv run graflow run workflow.yaml |
| 61 | +uv run hello.py |
61 | 62 | ``` |
62 | 63 |
|
63 | 64 | </TabItem> |
64 | 65 | </Tabs> |
65 | 66 |
|
66 | | -You should see output similar to: |
| 67 | +You should see: |
67 | 68 |
|
68 | 69 | ``` |
69 | | -[2025-01-01 12:00:00] Starting workflow: hello-world |
70 | | -[2025-01-01 12:00:00] Running task: greet |
71 | 70 | Hello, Graflow! |
72 | | -[2025-01-01 12:00:01] Task completed: greet |
73 | | -[2025-01-01 12:00:01] Workflow completed successfully |
| 71 | +Task completed with result: success |
| 72 | +``` |
| 73 | + |
| 74 | +## Your First Workflow |
| 75 | + |
| 76 | +Now let's chain multiple tasks into a workflow. Create `pipeline.py`: |
| 77 | + |
| 78 | +```python |
| 79 | +from graflow import task, workflow |
| 80 | + |
| 81 | +with workflow("simple_pipeline") as wf: |
| 82 | + |
| 83 | + @task |
| 84 | + def start(): |
| 85 | + print("Starting!") |
| 86 | + |
| 87 | + @task |
| 88 | + def middle(): |
| 89 | + print("Middle!") |
| 90 | + |
| 91 | + @task |
| 92 | + def end(): |
| 93 | + print("End!") |
| 94 | + |
| 95 | + # Define sequential pipeline: start -> middle -> end |
| 96 | + start >> middle >> end |
| 97 | + |
| 98 | + # Execute the workflow |
| 99 | + wf.execute() |
| 100 | +``` |
| 101 | + |
| 102 | +Run it: |
| 103 | + |
| 104 | +<Tabs> |
| 105 | + <TabItem value="pip" label="pip" default> |
| 106 | + |
| 107 | +```bash |
| 108 | +python pipeline.py |
74 | 109 | ``` |
75 | 110 |
|
76 | | -## Understanding the Output |
| 111 | + </TabItem> |
| 112 | + <TabItem value="uv" label="uv"> |
77 | 113 |
|
78 | | -Graflow provides detailed logging for every step: |
| 114 | +```bash |
| 115 | +uv run pipeline.py |
| 116 | +``` |
| 117 | + |
| 118 | + </TabItem> |
| 119 | +</Tabs> |
| 120 | + |
| 121 | +You should see: |
| 122 | + |
| 123 | +``` |
| 124 | +Starting! |
| 125 | +Middle! |
| 126 | +End! |
| 127 | +``` |
79 | 128 |
|
80 | | -- **Timestamps**: When each task started and completed |
81 | | -- **Task names**: Which task is currently running |
82 | | -- **Output**: The actual output from your scripts |
| 129 | +The `>>` operator chains tasks sequentially — `middle` runs after `start`, and `end` runs after `middle`. |
83 | 130 |
|
84 | 131 | ## Next Steps |
85 | 132 |
|
|
0 commit comments