https://dagster.io/ logo
#ask-ai
Title
# ask-ai
j

jasono

02/10/2024, 4:33 AM
How do I pass a value from a sensor to an asset job?
s

Scout

02/10/2024, 4:33 AM
To pass a value from a sensor to an asset job in Dagster, you can use the
RunRequest
object within the sensor's evaluation function to provide a
run_config
that specifies the configuration for the job. The
run_config
can include parameters that the job or its ops can consume. Here is an example from the documentation that demonstrates how to generate a
RunRequest
for every materialization for the asset key `my_table`:
Copy code
python from dagster import (     AssetKey,     EventLogEntry,     RunConfig,     SensorEvaluationContext,     asset_sensor, )  @asset_sensor(asset_key=AssetKey("my_table"), job=my_job) def my_asset_sensor(context: SensorEvaluationContext, asset_event: EventLogEntry):     assert asset_event.dagster_event and asset_event.dagster_event.asset_key     yield RunRequest(         run_key=context.cursor,         run_config=RunConfig(             ops={                 "read_materialization": {                     "config": {                         "asset_key": list(asset_event.dagster_event.asset_key.path)                     }                 }             }         ),     )
In this example, the
run_config
is provided as a parameter to
RunRequest
, and it includes a configuration for an op named
read_materialization
. The configuration for this op includes the
asset_key
that was part of the materialization event. When the sensor triggers and the job runs, the job will use the provided
run_config
to configure its ops accordingly. This allows you to pass values from the sensor to the job, and subsequently to the ops within the job. Remember to replace
"read_materialization"
with the actual name of the op in your job that needs to receive the configuration, and ensure that the configuration structure matches what your job expects.
10 Views