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

denton

02/19/2024, 6:47 PM
what is the difference between the
@sensor
decorator and the
@asset_sensor
decorator?
s

Scout

02/19/2024, 6:47 PM
The
@sensor
and
@asset_sensor
decorators in Dagster are used to define different types of sensors that can trigger pipeline runs based on certain conditions. The
@sensor
decorator is used to define a general sensor. The decorated function, known as the sensor's evaluation function, is periodically invoked by the Dagster scheduler. The evaluation function takes a
SensorEvaluationContext
object as an argument, which provides methods for interacting with the Dagster instance and scheduling pipeline runs. If the evaluation function determines that a pipeline run should be triggered, it yields a
RunRequest
object. If no run should be triggered, it can yield a
SkipReason
to log why the evaluation was skipped. The
@asset_sensor
decorator, on the other hand, is specifically used to define an asset sensor that monitors for materialization events of a particular asset. The evaluation function for an asset sensor takes a
SensorEvaluationContext
and an asset materialization event as arguments. Similar to the general sensor, the asset sensor's evaluation function can yield
RunRequest
objects to trigger pipeline runs or
SkipReason
objects if no runs should be triggered. However, the asset sensor is specifically focused on asset materialization events and is designed to respond to changes in the state of assets. In summary, the
@sensor
decorator is for general-purpose sensors that can be based on any logic, while the
@asset_sensor
decorator is specialized for sensors that are triggered by asset materialization events.
3 Views