Skip to main content

Trigger cross-job dependencies with Asset Sensors

Asset sensors in Dagster provide a powerful mechanism for monitoring asset materializations and triggering downstream computations or notifications based on those events.

This guide covers the most common use cases for asset sensors such as defining cross-job and cross-code location dependencies.

Prerequisites

Define cross-job and cross-code location dependencies

Asset Sensors enable dependencies across different jobs and even different code locations. This flexibility allows for more modular and decoupled workflows.

Here's a minimal example of an asset sensor that triggers a job when an asset is materialized. The daily_sales_data asset is in the same code location for this example, but the same pattern can be applied to assets in different code locations.

Simple Asset Sensor Example
Loading...

Customize evaluation logic

The evaluation function of an asset sensor can be customized to include custom logic for determining when to trigger a run. This allows for fine-grained control over the conditions under which downstream jobs are executed.

In this example, the @asset_sensor decorator allows you to define a custom evaluation function that returns a RunRequest object when the asset is materialized and certain metadata is present, otherwise it skips the run.

Asset Sensor with Custom Evaluation Logic
Loading...

Trigger a job with configuration

By providing a configuration to the RunRequest object, you can trigger a job with a specific configuration. This is useful when you want to trigger a job with custom parameters based on custom logic you define. For example, you might use a sensor to trigger a job when an asset is materialized, but also pass metadata about that materialization to the job.

Asset Sensor with Config
Loading...

Monitor multiple assets

The previous examples showed how to use a single asset sensor to monitor a single asset and trigger a job when it's materialized. This example uses a multi-asset sensor to monitor multiple assets and trigger a job when any of the monitored assets are materialized.

Multi-Asset Sensor
Loading...

Next steps