# ask-ai

Henry Tareque

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


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
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 = <|>('<>', json=payload)     # Handle the response as needed
In this example, when a job fails, the
function is called with the
, 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.