Re: [I] on_failure_callback is not called when task is manually marked as failed [airflow]

2024-04-15 Thread via GitHub


ephraimbuddy commented on issue #38935:
URL: https://github.com/apache/airflow/issues/38935#issuecomment-2055618135

   I think it might be worth it if you can create a feature request and explain 
how necessary this issue is, the use cases because I see it, that it's not 
required because the user is performing a manual action on the UI, what's the 
need to run the callback when same callback can be a task instead.
   
   closing since it's not a bug


-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [I] on_failure_callback is not called when task is manually marked as failed [airflow]

2024-04-15 Thread via GitHub


ephraimbuddy closed issue #38935: on_failure_callback is not called when task 
is manually marked as failed
URL: https://github.com/apache/airflow/issues/38935


-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [I] on_failure_callback is not called when task is manually marked as failed [airflow]

2024-04-14 Thread via GitHub


FFCMSouza commented on issue #38935:
URL: https://github.com/apache/airflow/issues/38935#issuecomment-2054223724

   Anyway, I managed to find a way to solve my problem overwriting the 
`on_kill` method in my spark operator.
   The only downside is that the `on_kill` method doesn't have access to the 
task context. To solve this problem, I created local variables on the `execute` 
method with the context information I need.
   
   ```
   def on_kill(self):
   logging.info('starting on_kill')
   cancel_step(self.project, self.dag_name, self.run_id, self.task_id)
   ```
   def execute(self, context):
   self.log.info("starting SparkToDataLake.execute")
   
   self.dag_name = context.get('task_instance').dag_id
   self.run_id = context.get('run_id')
   self.task_id = context.get('task_instance').task_id + 
str(context.get('task_instance').map_index)
   
![image](https://github.com/apache/airflow/assets/68713515/132a1c57-f738-44c2-b4ef-053c3d8787e2)
   
   PS: The `on_kill` method is also called on the `AirflowTaskTimeout` 
exception.


-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [I] on_failure_callback is not called when task is manually marked as failed [airflow]

2024-04-14 Thread via GitHub


FFCMSouza commented on issue #38935:
URL: https://github.com/apache/airflow/issues/38935#issuecomment-2054217500

   > There are no plans to change the behaviour at the moment. Also, I don't 
know why you would want the callback to run when you intentionally failed a task
   
   In my case, I use Airflow as an orchestrator to run Spark applications 
(spark-sql and spark-submit). When a task has failed or is marked as failed, in 
addition to notifying that the task has failed, I need to make sure that the 
corresponding step has been canceled in Spark. Most of the time, when a task 
actually fails, the cancel step operation is unnecessary, but this is not the 
case when a task is marked as failed.
   
   I don't think it's such a rare scenario, plus similar issues have been 
opened before. I believe this behavior change would be very welcome in future 
Airflow releases.


-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [I] on_failure_callback is not called when task is manually marked as failed [airflow]

2024-04-14 Thread via GitHub


ephraimbuddy commented on issue #38935:
URL: https://github.com/apache/airflow/issues/38935#issuecomment-2054154690

   > Yes, I saw that. So there is no intention to change this behavior? To me 
this doesn't make sense, marking a task as failed should trigger the failure 
callback. If that's the case, is there any workaround to do this? I'm trying to 
use the on_kill method to do this, does it make sense to you?
   
   There are no plans to change the behaviour at the moment. Also, I don't know 
why you would want the callback to run when you intentionally failed a task


-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [I] on_failure_callback is not called when task is manually marked as failed [airflow]

2024-04-12 Thread via GitHub


FFCMSouza commented on issue #38935:
URL: https://github.com/apache/airflow/issues/38935#issuecomment-2052409632

   Yes, I saw that. So there is no intention to change this behavior?
   To me this doesn't make sense, marking a task as failed should trigger the 
failure callback.
   If that's the case, is there any workaround to do this? I'm trying to use 
the on_kill method to do this, does it make sense to you?


-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [I] on_failure_callback is not called when task is manually marked as failed [airflow]

2024-04-12 Thread via GitHub


ephraimbuddy commented on issue #38935:
URL: https://github.com/apache/airflow/issues/38935#issuecomment-2052393366

   This behaviour is documented in the code 
https://github.com/apache/airflow/blob/5f6f4a5f4654d64efb4c0cabb6e0e054d13a2e0f/airflow/models/taskinstance.py#L2594-L2597.
   
   So it's not a bug 


-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [I] on_failure_callback is not called when task is manually marked as failed [airflow]

2024-04-11 Thread via GitHub


FFCMSouza commented on issue #38935:
URL: https://github.com/apache/airflow/issues/38935#issuecomment-2050273127

   I saw that on version 1.9.0, thats already a different type of exception for 
this cases.
   I believe that the following change could be made to fix that behavior:
   `except (AirflowFailException, AirflowSensorTimeout, 
AirflowTaskTerminated) as e:
   # If AirflowFailException is raised, task should not retry.
   # If a sensor in reschedule mode reaches timeout, task 
should not retry.
   self.handle_failure(e, test_mode, context, force_fail=True, 
session=session)
   session.commit()
   raise
   except (AirflowTaskTimeout, AirflowException) as e:
   if not test_mode:
   self.refresh_from_db(lock_for_update=True, 
session=session)
   # for case when task is marked as success/failed externally
   # or dagrun timed out and task is marked as skipped
   # current behavior doesn't hit the callbacks
   if self.state in State.finished:
   self.clear_next_method_args()
   session.merge(self)
   session.commit()
   return None
   else:
   self.handle_failure(e, test_mode, context, 
session=session)
   session.commit()
   raise`


-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [I] on_failure_callback is not called when task is manually marked as failed [airflow]

2024-04-11 Thread via GitHub


boring-cyborg[bot] commented on issue #38935:
URL: https://github.com/apache/airflow/issues/38935#issuecomment-2049804187

   Thanks for opening your first issue here! Be sure to follow the issue 
template! If you are willing to raise PR to address this issue please do so, no 
need to wait for approval.
   


-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org