Skip to content

Commit e6a4fbd

Browse files
committed
Adds snippets for all step methods and event param
1 parent 3aff634 commit e6a4fbd

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

src/content/docs/workflows/python/bindings.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ Values returned from steps need to be converted into Javascript objects using `t
6262

6363
:::
6464

65+
### `event` parameter
66+
67+
The `event` parameter is a dictionary that contains the payload passed to the workflow instance, along with other metadata:
68+
69+
* <code>payload</code> - the payload passed to the workflow instance.
70+
* <code>timestamp</code> - the timestamp that the workflow was triggered.
71+
* <code>instanceId</code> - the ID of the current workflow instance.
72+
* <code>workflowName</code> - the name of the workflow.
73+
6574

6675
And this is how you use the payload in your workflow:
6776

src/content/docs/workflows/python/dag.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ class MyWorkflow(WorkflowEntrypoint):
3333

3434
Having `concurrent=True` allows the dependencies to be resolved concurrently. If one of the callables passed to `depends` has already completed, it will be skipped and its return value will be reused.
3535

36-
This pattern is usefull for diamond shaped workflows, where a step depends on two or more other steps that can run concurrently.
36+
This pattern is usefull for diamond shaped workflows, where a step depends on two or more other steps that can run concurrently.

src/content/docs/workflows/python/run.mdx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,52 @@ Refer to [Pyodide's documentation](https://pyodide.org/en/stable/usage/type-conv
3737
* `name` - the name of the step.
3838
* `duration` - the duration to sleep until, in either seconds or as a `WorkflowDuration` compatible string.
3939

40+
```python
41+
async def on_run(self, event, step):
42+
await step.sleep("my-sleep-step", "10 seconds")
43+
```
44+
4045
* <code>step.sleep_until(name, timestamp)</code>
4146

4247
* `name` - the name of the step.
43-
* `timestamp` - a `datetime.date` object or seconds from the Unix epoch to sleep the Workflow instance until.
48+
* `timestamp` - a `datetime.date` object or seconds from the Unix epoch to sleep the workflow instance until.
49+
50+
```python
51+
async def on_run(self, event, step):
52+
await step.sleep_until("my-sleep-step", datetime.datetime.now() + datetime.timedelta(seconds=10))
53+
```
4454

4555
* <code>step.wait_for_event(name, event_type, timeout="24 hours")</code>
4656

4757
* `name` - the name of the step.
4858
* `event_type` - the type of event to wait for.
49-
* `timeout` - the timeout for the `waitForEvent` call. The default timeout is 24 hours.
59+
* `timeout` - the timeout for the `wait_for_event` call. The default timeout is 24 hours.
60+
61+
```python
62+
async def on_run(self, event, step):
63+
await step.wait_for_event("my-wait-for-event-step", "my-event-type")
64+
```
5065

5166
## Error Handling
5267

5368
Workflows semantics allow users to catch exceptions that get thrown to the top level.
5469

70+
```python
71+
async def on_run(self, event, step):
72+
async def await_step(fn):
73+
try:
74+
return await fn()
75+
except Exception as e:
76+
print(f"Successfully caught {type(e).__name__}: {e}")
77+
78+
@step.do("my_failing")
79+
async def my_failing():
80+
print("Executing my_failing")
81+
raise TypeError("Intentional error in my_failing")
82+
83+
await_step(my_failing)
84+
```
85+
5586
:::note
5687
Catching specific exceptions within an `except` block may not work, as some Python errors will not be re-instantiated into the same type of error when they are passed through the RPC layer.
5788
:::

0 commit comments

Comments
 (0)