Andreas
03/06/2024, 2:23 PMScout
03/06/2024, 2:23 PMRunRequest
to trigger the job. Here's a step-by-step guide based on the documentation: 1. Define the Job: First, you need to define a job that includes the assets you want to run. A job is a collection of assets that you want to execute together. 2. Create a Sensor: Define a sensor using the @sensor
decorator. The sensor function will periodically check for certain conditions and decide whether to trigger a job run. 3. Return a RunRequest: Inside the sensor function, you will check for the conditions you're interested in (like a new file in a directory, a certain time of day, etc.). If the conditions are met, you will return a RunRequest
object that includes the name of the job to run and any necessary run configuration. Here is an example of how you might define a sensor to trigger a job: python from dagster import sensor, RunRequest, DefaultSensorStatus @sensor(job=my_job, minimum_interval_seconds=30) def my_sensor(context): # Your logic to check conditions goes here if my_condition_is_met(): return RunRequest( run_key="unique_run_key_for_this_trigger", # Unique identifier for this run request run_config={"ops": {"my_op": {"config": "value"}}}, # Optional: Configuration for the job ) # If conditions are not met, return nothing to avoid triggering a run
In this example, my_job
is the job you've defined elsewhere that contains the assets you want to execute. The my_sensor
function will be evaluated every 30 seconds (as specified by minimum_interval_seconds
), and when my_condition_is_met()
returns True
, it will trigger a run of my_job
with the specified run configuration. Remember to replace my_condition_is_met()
with your actual condition-checking logic and provide the appropriate run configuration for your job. Please note that the code example provided is a general template and should be adapted to fit your specific use case. For more detailed information and examples, you should refer to the [Sensors documentation](https://docs.dagster.io/concepts/partitions-schedules-sensors/sensors).