dagster sensor start a job after a job example
# ask-ai
a
dagster sensor start a job after a job example
s
To create a sensor in Dagster that starts a job after another job has completed, you can use the
@run_status_sensor
decorator. This decorator allows you to define a sensor that reacts to a specific status of a job execution, such as success or failure. When the specified job reaches the given status, the sensor will trigger the execution of another job. Here's an example from the documentation on how to define such a sensor:
Copy code
python from dagster import run_status_sensor, DagsterRunStatus, RunRequest  @run_status_sensor(     run_status=DagsterRunStatus.SUCCESS,     monitored_jobs=[job_1],  # Replace with the actual job you want to monitor     request_job=job_2,       # Replace with the job you want to start after job_1 completes ) def job_2_starter_sensor(context):     # This function is called when job_1 completes successfully.     # You can add additional logic here if needed.     return RunRequest(run_key=None, run_config={})  # Replace with the actual run config for job_2
In this example: -
job_1
is the job that you want to monitor for successful completion. -
job_2
is the job that you want to start after
job_1
has completed successfully. -
run_status=DagsterRunStatus.SUCCESS
specifies that the sensor should trigger when
job_1
completes with a success status. -
monitored_jobs=[job_1]
is a list of jobs that the sensor will monitor. -
request_job=job_2
specifies the job that should be executed when the sensor triggers. -
RunRequest
is used to create a request to run
job_2
. You can specify a
run_key
to uniquely identify the run and a
run_config
to provide configuration for the run. Please replace
job_1
and
job_2
with the actual job definitions you have in your Dagster project, and provide the necessary run configuration for
job_2
if needed. Remember to import the necessary modules and job definitions to use this example in your code.