Updating the Definitions object
As with your other Dagster definitions, the final step is to add the sensor, its related asset, and job into the Definitions object. This will be done in the top-level __init__.py file.
Import the new asset, job, and sensor into the
__init__.pyfile by updating the following imports:from .assets import trips, metrics, requests ... from .jobs import trip_update_job, weekly_update_job, adhoc_request_job ... from .sensors import adhoc_request_sensorBeneath
metric_assets, create arequest_assetsvariable that loads the assets fromrequests:request_assets = load_assets_from_modules([requests])Add the
adhoc_request_jobtoall_jobs:all_jobs = [trip_update_job, weekly_update_job, adhoc_request_job]Beneath
all_schedules, create a new variable namedall_sensorsand add theadhoc_request_sensorto it:all_sensors = [adhoc_request_sensor]Lastly, update the
Definitionsobject by:Adding the new asset (
request_assets) to theassetsparameter:assets=[*trip_assets, *metric_assets, *request_assets],Adding the
sensorsparameter and setting it toall_sensors:sensors=all_sensors,
At this point, __init__.py should look like this:
from dagster import Definitions, load_assets_from_modules
from .assets import trips, metrics, requests
from .resources import database_resource
from .jobs import trip_update_job, weekly_update_job, adhoc_request_job
from .schedules import trip_update_schedule, weekly_update_schedule
from .sensors import adhoc_request_sensor
trip_assets = load_assets_from_modules([trips])
metric_assets = load_assets_from_modules([metrics])
request_assets = load_assets_from_modules([requests])
all_jobs = [trip_update_job, weekly_update_job, adhoc_request_job]
all_schedules = [trip_update_schedule, weekly_update_schedule]
all_sensors = [adhoc_request_sensor]
defs = Definitions(
assets=[*trip_assets, *metric_assets, *request_assets],
resources={
"database": database_resource,
},
jobs=all_jobs,
schedules=all_schedules,
sensors=all_sensors
)
Congratulations on creating a sensor! We’ll discuss how to enable the sensor in a bit, but let’s start by going through the Dagster UI.