diff --git a/docs/docs-next/docs/code_examples/guides/automation/asset-sensor-with-config.py b/docs/docs-next/docs/code_examples/guides/automation/asset-sensor-with-config.py new file mode 100644 index 0000000000000..b1c01c332b728 --- /dev/null +++ b/docs/docs-next/docs/code_examples/guides/automation/asset-sensor-with-config.py @@ -0,0 +1,52 @@ +from dagster import ( + AssetExecutionContext, + AssetKey, + Definitions, + EventLogEntry, + RunRequest, + SensorEvaluationContext, + asset, + asset_sensor, + define_asset_job, +) + + +@asset +def daily_sales_data(context: AssetExecutionContext): + context.log.info("Asset to watch") + + +@asset +def weekly_report(context: AssetExecutionContext): + context.log.info("Asset to trigger") + + +my_job = define_asset_job("my_job", [weekly_report]) + + +# highlight-start +@asset_sensor(asset_key=AssetKey("daily_sales_data"), job=my_job) +def daily_sales_data_sensor(context: SensorEvaluationContext, asset_event: EventLogEntry): + # This satisifies the type checker. Asset events are guaranteed to have a dagster_event and asset_key. + assert asset_event.dagster_event is not None + assert asset_event.dagster_event.asset_key is not None + + return RunRequest( + run_key=context.cursor, + run_config={ + "ops": { + "read_materialization": { + "config": { + "asset_key": asset_event.dagster_event.asset_key.path, + } + } + } + }, + ) # highlight-end + + +defs = Definitions( + assets=[daily_sales_data, weekly_report], + jobs=[my_job], + sensors=[daily_sales_data_sensor], +) diff --git a/docs/docs-next/docs/code_examples/guides/automation/simple-asset-sensor-example.py b/docs/docs-next/docs/code_examples/guides/automation/simple-asset-sensor-example.py new file mode 100644 index 0000000000000..ad7c30f647118 --- /dev/null +++ b/docs/docs-next/docs/code_examples/guides/automation/simple-asset-sensor-example.py @@ -0,0 +1,36 @@ +from dagster import ( + AssetExecutionContext, + AssetKey, + Definitions, + RunRequest, + asset, + asset_sensor, + define_asset_job, +) + + +@asset +def daily_sales_data(context: AssetExecutionContext): + context.log.info("Asset to watch") + + +@asset +def weekly_report(context: AssetExecutionContext): + context.log.info("Asset to trigger") + + +my_job = define_asset_job("my_job", [weekly_report]) + + +# highlight-start +@asset_sensor(asset_key=AssetKey("daily_sales_data"), job_name="my_job") +def daily_sales_data_sensor(): + return RunRequest() + # highlight-end + + +defs = Definitions( + assets=[daily_sales_data, weekly_report], + jobs=[my_job], + sensors=[daily_sales_data_sensor], +) diff --git a/docs/docs-next/docs/guides/automation/simple-schedule-example.py b/docs/docs-next/docs/code_examples/guides/automation/simple-schedule-example.py similarity index 100% rename from docs/docs-next/docs/guides/automation/simple-schedule-example.py rename to docs/docs-next/docs/code_examples/guides/automation/simple-schedule-example.py diff --git a/docs/docs-next/docs/guides/automation/simple-sensor-example.py b/docs/docs-next/docs/code_examples/guides/automation/simple-sensor-example.py similarity index 100% rename from docs/docs-next/docs/guides/automation/simple-sensor-example.py rename to docs/docs-next/docs/code_examples/guides/automation/simple-sensor-example.py diff --git a/docs/docs-next/docs/guides/data-assets/passing-data-assets/passing-data-avoid.py b/docs/docs-next/docs/code_examples/guides/data-assets/passing-data-assets/passing-data-avoid.py similarity index 100% rename from docs/docs-next/docs/guides/data-assets/passing-data-assets/passing-data-avoid.py rename to docs/docs-next/docs/code_examples/guides/data-assets/passing-data-assets/passing-data-avoid.py diff --git a/docs/docs-next/docs/guides/data-assets/passing-data-assets/passing-data-explicit.py b/docs/docs-next/docs/code_examples/guides/data-assets/passing-data-assets/passing-data-explicit.py similarity index 100% rename from docs/docs-next/docs/guides/data-assets/passing-data-assets/passing-data-explicit.py rename to docs/docs-next/docs/code_examples/guides/data-assets/passing-data-assets/passing-data-explicit.py diff --git a/docs/docs-next/docs/guides/data-assets/passing-data-assets/passing-data-io-manager.py b/docs/docs-next/docs/code_examples/guides/data-assets/passing-data-assets/passing-data-io-manager.py similarity index 100% rename from docs/docs-next/docs/guides/data-assets/passing-data-assets/passing-data-io-manager.py rename to docs/docs-next/docs/code_examples/guides/data-assets/passing-data-assets/passing-data-io-manager.py diff --git a/docs/docs-next/docs/guides/data-assets/passing-data-assets/passing-data-rewrite-assets.py b/docs/docs-next/docs/code_examples/guides/data-assets/passing-data-assets/passing-data-rewrite-assets.py similarity index 100% rename from docs/docs-next/docs/guides/data-assets/passing-data-assets/passing-data-rewrite-assets.py rename to docs/docs-next/docs/code_examples/guides/data-assets/passing-data-assets/passing-data-rewrite-assets.py diff --git a/docs/docs-next/docs/guides/automation/simple-asset-sensor-example.py b/docs/docs-next/docs/guides/automation/simple-asset-sensor-example.py deleted file mode 100644 index 3432bb604d190..0000000000000 --- a/docs/docs-next/docs/guides/automation/simple-asset-sensor-example.py +++ /dev/null @@ -1,36 +0,0 @@ -from dagster import ( - AssetExecutionContext, - AssetKey, - Definitions, - RunRequest, - asset, - asset_sensor, - define_asset_job, -) - - -@asset -def asset_to_watch(context: AssetExecutionContext): - context.log.info("Asset to watch") - - -@asset -def asset_to_trigger(context: AssetExecutionContext): - context.log.info("Asset to trigger") - - -my_job = define_asset_job("my_job", [asset_to_trigger]) - - -# highlight-start -@asset_sensor(asset_key=AssetKey("asset_to_watch"), job_name="my_job") -def my_asset_sensor(): - yield RunRequest() - # highlight-end - - -defs = Definitions( - assets=[asset_to_watch, asset_to_trigger], - jobs=[my_job], - sensors=[my_asset_sensor], -)