If a sensor evaluation doesn't yield any run requests, it can instead yield a skip reason to log why the evaluation was skipped or why there were no events to be processed.
The decorator used to define an asset sensor. The decorated function is an evaluation function that takes in a SensorEvaluationContext and an asset materialization event. The decorator returns an AssetSensorDefinition
A special sensor definition class for asset sensors. You almost never want to use initialize this class directly. Instead, you should use the @asset_sensor which returns a AssetSensorDefinition
The decorator used to define a freshness policy sensor. The decorated function is an evaluation function that takes in a FreshnessPolicySensorContext. The decorator returns a FreshnessPolicySensorDefinition
A special sensor definition class for freshness policy sensors. You almost never want to use initialize this class directly. Instead, you should use the @freshness_policy_sensor which returns a FreshnessPolicySensorDefinition
An asset sensor checks for new AssetMaterialization events for a particular asset key. This can be used to kick off a job that computes downstream assets or notifies appropriate stakeholders.
One benefit of this pattern is that it enables cross-job and even cross-code-location dependencies. Each job run instigated by an asset sensor is agnostic to the job that caused it.
Dagster provides a special asset sensor definition format for sensors that fire a single RunRequest based on a single asset materialization. Here is an example of a sensor that generates a RunRequest for every materialization for the asset key my_table:
A freshness policy sensor checks the freshness of a given selection of assets on each tick, and performs some action in response to that status.
FreshnessPolicySensorContext has a current_minutes_late property, specifying how many minutes late the asset is with respect to its FreshnessPolicy, as well as previous_minutes_late, the number of minutes late that asset was on the previous sensor tick. Each tick, the decorated function will be run for each asset within the asset_selection that has a FreshnessPolicy defined.
Currently, freshness policy sensors do not support returning or yielding values (such as RunRequests) from their execution function.
Here is an example of a sensor that will send a single alert once an asset is 10 minutes later than its configured policy allows, and a single alert once that asset is on time again.
from dagster import FreshnessPolicySensorContext, freshness_policy_sensor
@freshness_policy_sensor(asset_selection=AssetSelection.all())defmy_freshness_alerting_sensor(context: FreshnessPolicySensorContext):if context.minutes_overdue isNoneor context.previous_minutes_overdue isNone:returnif context.minutes_overdue >=10and context.previous_minutes_overdue <10:
send_alert(f"Asset with key {context.asset_key} is now more than 10 minutes overdue.")elif context.minutes_overdue ==0and context.previous_minutes_overdue >=10:
send_alert(f"Asset with key {context.asset_key} is now on time.")