Code Monkey home page Code Monkey logo

Comments (8)

boring-cyborg avatar boring-cyborg commented on May 24, 2024

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.

from airflow.

FFCMSouza avatar FFCMSouza commented on May 24, 2024

I saw that in version 1.9.0, there is already a different type of exception for this case.
I believe that the following change could be made to fix this behavior:

+          except (AirflowFailException, AirflowSensorTimeout, AirflowTaskTerminated) as e:
-          except (AirflowFailException, AirflowSensorTimeout) 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:
-          except (AirflowTaskTimeout, AirflowException, AirflowTaskTerminated) 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

from airflow.

ephraimbuddy avatar ephraimbuddy commented on May 24, 2024

This behaviour is documented in the code

# 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:
.

So it's not a bug

from airflow.

FFCMSouza avatar FFCMSouza commented on May 24, 2024

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?

from airflow.

ephraimbuddy avatar ephraimbuddy commented on May 24, 2024

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

from airflow.

FFCMSouza avatar FFCMSouza commented on May 24, 2024

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.

from airflow.

FFCMSouza avatar FFCMSouza commented on May 24, 2024

Anyway, I managed 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 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

PS: The on_kill method is also called on the AirflowTaskTimeout exception.

from airflow.

ephraimbuddy avatar ephraimbuddy commented on May 24, 2024

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

from airflow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.