VVildVVolf commented on issue #31180:
URL: https://github.com/apache/airflow/issues/31180#issuecomment-1546778643

   Hi @funes79 ,
   
   Could you please try `v2.6.1*` ?
   
   I checked with recent master (584a9f5dae5b29a1968fbdbc9b1edd01ae2be4d2) and 
the listener is being triggered. Here is the sample I used:
   DAG: test_dag.py
   ```
   from airflow import DAG
   from airflow.operators.python import PythonOperator
   from datetime import datetime
   
   def _func():
       raise Exception("")
   
   with DAG("my_dag",
       start_date=datetime(2011, 11 ,11),
       schedule_interval='@daily',
       catchup=False
   ) as dag:
       pythonOperator = PythonOperator(
           task_id="task",
           python_callable=_func,
       )
   ```
   plugin: p.py
   ```
   from airflow.listeners import hookimpl
   from airflow.plugins_manager import AirflowPlugin
   import logging
   
   class Plg(AirflowPlugin):
       class Listener:
           @hookimpl
           def on_task_instance_failed(previous_state, task_instance, session):
               """
               This method is called when task state changes to FAILED.
               Through callback, parameters like previous_task_state, 
task_instance object can be accessed.
               This will give more information about current task_instance that 
has failed its dag_run,
               task and dag information.
               """
               logging.info("on_task_instance_failed")
   
           @hookimpl
           def on_dag_run_failed(dag_run, msg: str):
               """
               This method is called when dag run state changes to FAILED.
               """
               logging.info("on_dag_run_failed")
   
       name = "name"
       listeners = [Listener()]
   ```
   
   and after triggering, scheduller's logs show:
   <img width="721" alt="image" 
src="https://github.com/apache/airflow/assets/5997744/0dd7b882-7ead-488b-96b5-b7801a0ae583";>
   _P.S. The screenshot shows logs from breeze console, by default scheduler 
should write to something like `$AIRFLOW_HOME/logs/scheduler/`_


-- 
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