forked from dagster-io/dagster
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
output_required on asset decorator (dagster-io#9327)
- Loading branch information
jamiedemaria
authored
Aug 16, 2022
1 parent
d61fc55
commit 623d240
Showing
6 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
examples/docs_snippets/docs_snippets/concepts/assets/conditional_materialization.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import random | ||
|
||
from dagster import Output, asset | ||
|
||
# start_conditional | ||
|
||
|
||
@asset(output_required=False) | ||
def may_not_materialize(): | ||
# to simulate an asset that may not always materialize. | ||
random.seed() | ||
if random.randint(1, 10) < 5: | ||
yield Output([1, 2, 3, 4]) | ||
|
||
|
||
@asset | ||
def downstream(may_not_materialize): | ||
# will not run when may_not_materialize doesn't materialize the asset | ||
return may_not_materialize + [5] | ||
|
||
|
||
# end_conditional |
38 changes: 38 additions & 0 deletions
38
python_modules/dagster-test/dagster_test/toys/conditional_assets.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import random | ||
|
||
from dagster import AssetKey, Output, RunRequest, asset, asset_sensor, job, op | ||
|
||
|
||
@asset(output_required=False) | ||
def may_not_materialize(context): | ||
random.seed() | ||
rand_num = random.randint(1, 10) | ||
context.log.info( | ||
f"Random number is {rand_num}. Asset will {'not' if rand_num >=5 else ''} materialize." | ||
) | ||
if rand_num < 5: | ||
yield Output([1, 2, 3]) | ||
|
||
|
||
@asset | ||
def downstream_conditional(may_not_materialize): | ||
return may_not_materialize + [4] | ||
|
||
|
||
@op | ||
def success_op(context): | ||
context.log.info("success!") | ||
|
||
|
||
@job | ||
def success_job(): | ||
success_op() | ||
|
||
|
||
@asset_sensor(asset_key=AssetKey("may_not_materialize"), job=success_job) | ||
def may_not_materialize_sensor(context, asset_event): # pylint: disable=unused-argument | ||
return RunRequest(run_key=None) | ||
|
||
|
||
def get_conditional_assets_repo(): | ||
return [may_not_materialize, downstream_conditional, may_not_materialize_sensor, success_job] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters