mandeepzemo commented on issue #54332:
URL: https://github.com/apache/airflow/issues/54332#issuecomment-3200293705

   @plovegro 
   
   I tested using the below code with on_dag_run_success, with slight changes 
as per your sample, and it is still working fine.
   
   I also noticed that the DAG listener logs are properly displaying in the 
scheduler terminal (screenshot attached for reference).
   
   Please check with a similar approach, and if you still face the issue, 
kindly share your complete listener file.
   
   
   **sample_test_listener.py**
   ```
   import logging
   import requests
   from airflow.listeners import hookimpl
   from airflow.models.dagrun import DagRun
   
   logger = logging.getLogger(__name__)
   
   class DebugSampleTaskListener:
       """Debug listener that logs task and DAG run state changes."""
       
       @hookimpl
       def on_dag_run_success(dag_run: DagRun, msg: str):
           """
           This method is called when dag run state changes to SUCCESS.
           """
           logger.info("Dag run in success state")
           start_date = getattr(dag_run, 'start_date', 'N/A')
           end_date = getattr(dag_run, 'end_date', 'N/A')
           try:
               # It's good practice to include a timeout and check the response
               url = "https://jsonplaceholder.typicode.com/todos/1";
               response = requests.get(url, timeout=10)
               response.raise_for_status()  # Raise an error for 4xx/5xx 
responses
               data = response.json()
               logger.info("Response: %s", data)
               logger.info("[DEBUG LISTENER] Dag run in success state " + 
str(data))
               return "Dag Listener running in success state " + str(data)
           
           except requests.exceptions.RequestException as e:
               logger.error(
                   "Failed to send webhook for task '%s': %s",
               1,
                   e,
               )
   
           logger.info(f"Dag run start:{start_date} end:{end_date}")
   
   
   debug_sample_task_listener = DebugSampleTaskListener()
   ```
   
   **output**
   
   <img width="1910" height="185" alt="Image" 
src="https://github.com/user-attachments/assets/5c738d34-e6d9-40f6-bf03-5e9a625a3b48";
 />


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to