Changeset View
Changeset View
Standalone View
Standalone View
docs/content/concepts/solids-pipelines/solid-events.mdx
Show First 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | |||||
```python file=/concepts/solids_pipelines/solid_events.py startafter=start_solid_output_3 endbefore=end_solid_output_3 | ```python file=/concepts/solids_pipelines/solid_events.py startafter=start_solid_output_3 endbefore=end_solid_output_3 | ||||
@solid | @solid | ||||
def my_metadata_output(context): | def my_metadata_output(context): | ||||
df = get_some_data() | df = get_some_data() | ||||
yield Output( | yield Output( | ||||
df, | df, | ||||
metadata={ | metadata={ | ||||
"text_metadata": "Text-based metadata for this event", | "text_metadata": "Text-based metadata for this event", | ||||
"dashboard_url": EventMetadata.url("http://mycoolsite.com/url_for_my_data"), | "dashboard_url": EventMetadata.url( | ||||
"http://mycoolsite.com/url_for_my_data" | |||||
), | |||||
"raw_count": len(df), | "raw_count": len(df), | ||||
"size (bytes)": calculate_bytes(df), | "size (bytes)": calculate_bytes(df), | ||||
}, | }, | ||||
) | ) | ||||
``` | ``` | ||||
### Asset Materializations | ### Asset Materializations | ||||
Show All 30 Lines | def my_metadata_materialization_solid(context): | ||||
df = read_df() | df = read_df() | ||||
remote_storage_path = persist_to_storage(df) | remote_storage_path = persist_to_storage(df) | ||||
yield AssetMaterialization( | yield AssetMaterialization( | ||||
asset_key="my_dataset", | asset_key="my_dataset", | ||||
description="Persisted result to storage", | description="Persisted result to storage", | ||||
metadata={ | metadata={ | ||||
"text_metadata": "Text-based metadata for this event", | "text_metadata": "Text-based metadata for this event", | ||||
"path": EventMetadata.path(remote_storage_path), | "path": EventMetadata.path(remote_storage_path), | ||||
"dashboard_url": EventMetadata.url("http://mycoolsite.com/url_for_my_data"), | "dashboard_url": EventMetadata.url( | ||||
"http://mycoolsite.com/url_for_my_data" | |||||
), | |||||
"size (bytes)": calculate_bytes(df), | "size (bytes)": calculate_bytes(df), | ||||
}, | }, | ||||
) | ) | ||||
yield Output(remote_storage_path) | yield Output(remote_storage_path) | ||||
``` | ``` | ||||
### Expectation Results | ### Expectation Results | ||||
Show All 17 Lines | |||||
@solid | @solid | ||||
def my_metadata_expectation_solid(context, df): | def my_metadata_expectation_solid(context, df): | ||||
df = do_some_transform(df) | df = do_some_transform(df) | ||||
yield ExpectationResult( | yield ExpectationResult( | ||||
success=len(df) > 0, | success=len(df) > 0, | ||||
description="ensure dataframe has rows", | description="ensure dataframe has rows", | ||||
metadata={ | metadata={ | ||||
"text_metadata": "Text-based metadata for this event", | "text_metadata": "Text-based metadata for this event", | ||||
"dashboard_url": EventMetadata.url("http://mycoolsite.com/url_for_my_data"), | "dashboard_url": EventMetadata.url( | ||||
"http://mycoolsite.com/url_for_my_data" | |||||
), | |||||
"raw_count": len(df), | "raw_count": len(df), | ||||
"size (bytes)": calculate_bytes(df), | "size (bytes)": calculate_bytes(df), | ||||
}, | }, | ||||
) | ) | ||||
yield Output(df) | yield Output(df) | ||||
``` | ``` | ||||
## Exceptions | ## Exceptions | ||||
Show All 12 Lines | |||||
def my_failure_solid(): | def my_failure_solid(): | ||||
path = "/path/to/files" | path = "/path/to/files" | ||||
my_files = get_files(path) | my_files = get_files(path) | ||||
if len(my_files) == 0: | if len(my_files) == 0: | ||||
raise Failure( | raise Failure( | ||||
description="No files to process", | description="No files to process", | ||||
metadata={ | metadata={ | ||||
"filepath": EventMetadata.path(path), | "filepath": EventMetadata.path(path), | ||||
"dashboard_url": EventMetadata.url("http://mycoolsite.com/failures"), | "dashboard_url": EventMetadata.url( | ||||
"http://mycoolsite.com/failures" | |||||
), | |||||
}, | }, | ||||
) | ) | ||||
return some_calculation(my_files) | return some_calculation(my_files) | ||||
``` | ``` | ||||
#### Attaching Metadata to Failures | #### Attaching Metadata to Failures | ||||
As is the case with many Dagster-provided classes, you can attach a list <PyObject object="EventMetadataEntry"/> denoting an arbitrary set of metadata relevant to the failure. | As is the case with many Dagster-provided classes, you can attach a list <PyObject object="EventMetadataEntry"/> denoting an arbitrary set of metadata relevant to the failure. | ||||
```python file=/concepts/solids_pipelines/solid_events.py startafter=start_failure_metadata_solid endbefore=end_failure_metadata_solid | ```python file=/concepts/solids_pipelines/solid_events.py startafter=start_failure_metadata_solid endbefore=end_failure_metadata_solid | ||||
@solid | @solid | ||||
def my_failure_metadata_solid(): | def my_failure_metadata_solid(): | ||||
path = "/path/to/files" | path = "/path/to/files" | ||||
my_files = get_files(path) | my_files = get_files(path) | ||||
if len(my_files) == 0: | if len(my_files) == 0: | ||||
raise Failure( | raise Failure( | ||||
description="No files to process", | description="No files to process", | ||||
metadata={ | metadata={ | ||||
"filepath": EventMetadata.path(path), | "filepath": EventMetadata.path(path), | ||||
"dashboard_url": EventMetadata.url("http://mycoolsite.com/failures"), | "dashboard_url": EventMetadata.url( | ||||
"http://mycoolsite.com/failures" | |||||
), | |||||
}, | }, | ||||
) | ) | ||||
return some_calculation(my_files) | return some_calculation(my_files) | ||||
``` | ``` | ||||
### Retry Requests | ### Retry Requests | ||||
<PyObject object="RetryRequested" /> exceptions are useful when you experience failures | <PyObject object="RetryRequested" /> exceptions are useful when you experience failures | ||||
Show All 16 Lines |