https://dagster.io/ logo
#ask-ai
Title
# ask-ai
h

Henry Tareque

02/16/2024, 8:24 PM
@Scout Can you write a sensor that makes an HTTP request on job failures
s

Scout

02/16/2024, 8:24 PM
Yes, you can write a sensor in Dagster that reacts to job failures and makes an HTTP request. You would use the
@run_failure_sensor
decorator to create a sensor that triggers when a job fails. Within the decorated function, you can include the logic to make an HTTP request. Here's a high-level example based on the documentation:
Copy code
python import requests from dagster import run_failure_sensor, RunFailureSensorContext  @run_failure_sensor def my_failure_sensor(context: RunFailureSensorContext):     job_name = context.dagster_run.pipeline_name     failure_info = context.failure_event.message     # Construct your HTTP request payload based on the failure information     payload = {         'job_name': job_name,         'failure_info': failure_info,     }     # Make the HTTP request to your desired endpoint     response = <http://requests.post|requests.post>('<http://your-endpoint.com/notify>', json=payload)     # Handle the response as needed
In this example, when a job fails, the
my_failure_sensor
function is called with the
RunFailureSensorContext
, which contains information about the failed run. The function then constructs a payload with the job name and failure information and sends an HTTP POST request to a specified endpoint. Please note that this is a conceptual example to illustrate how you might structure the sensor. You would need to adapt the payload and the endpoint to your specific use case. Additionally, you should handle any potential exceptions that might occur during the HTTP request, such as network issues or errors returned by the endpoint.
4 Views