Skip to content

Commit

Permalink
[docs] - Add retries to Asset docs (dagster-io#18515)
Browse files Browse the repository at this point in the history
## Summary & Motivation

This PR adds a section to the SDA concept page that demonstrates how to
use `RetryPolicy` with the asset decorator.

## How I Tested These Changes

Added a test; ran using Pytest
  • Loading branch information
erinkcochran87 authored and zyd14 committed Jan 20, 2024
1 parent ee69ede commit b91bd70
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/content/concepts/assets/software-defined-assets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,28 @@ def multi_asset_with_versions():

Just as with regular assets, these versions are attached to the `AssetMaterialization` objects for each of the constituent assets and represented in the UI.

### Retrying failed assets

If an exception occurs during asset execution, you can use a <PyObject module="dagster" object="RetryPolicy" /> to automatically retry the asset within the same run.

In the following example, we've specified the number of times to retry and how long to wait between retries:

```python file=/concepts/assets/asset_retry.py
from dagster import Backoff, Jitter, RetryPolicy, RetryRequested, asset


@asset(
retry_policy=RetryPolicy(
max_retries=3,
delay=0.2, # 200ms
backoff=Backoff.EXPONENTIAL,
jitter=Jitter.PLUS_MINUS,
)
)
def retried_asset():
return "Retry me!"
```

---

## Viewing and materializing assets in the UI
Expand Down
15 changes: 15 additions & 0 deletions docs/content/concepts/ops-jobs-graphs/op-retries.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,18 @@ def manual():
```

Using `raise from` will ensure the original exceptions information is captured by Dagster.

---

## Related

<ArticleList>
<ArticleListItem
title="Ops"
href="/concepts/ops-jobs-graphs/ops"
></ArticleListItem>
<ArticleListItem
title="Asset retries"
href="/concepts/assets/software-defined-assets#retrying-failed-assets"
></ArticleListItem>
</ArticleList>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from dagster import Backoff, Jitter, RetryPolicy, RetryRequested, asset


@asset(
retry_policy=RetryPolicy(
max_retries=3,
delay=0.2, # 200ms
backoff=Backoff.EXPONENTIAL,
jitter=Jitter.PLUS_MINUS,
)
)
def retried_asset():
return "Retry me!"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from dagster import materialize
from docs_snippets.concepts.assets.asset_retry import retried_asset


def test_retry_examples():
# just that it runs
assert materialize([retried_asset])

0 comments on commit b91bd70

Please sign in to comment.