kaxil opened a new pull request, #53058:
URL: https://github.com/apache/airflow/pull/53058

   …illed
   
   Until https://github.com/apache/airflow/issues/44354 is implemented, tasks 
killed externally or when supervisor process dies unexpectedly, users have no 
way of knowing this happened.
   
   This has been a blocker for Airflow 3.0 adoption for some:
   
   - https://github.com/apache/airflow/issues/44354
   - https://apache-airflow.slack.com/archives/C07813CNKA8/p1751057525231389
   
   https://github.com/apache/airflow/issues/44354 is more involved and we might 
not get to it for Airflow 3.1 -- so this is a good fix until then similar to 
how we run Dag Run callback.
   
   Ran a example DAG:
   
   ```py
   import time
   
   from airflow.sdk import dag
   from airflow.providers.standard.operators.python import PythonOperator
   @dag
   def my_dag():
   
       def fail_cb(context):
           print("From inside the callback")
           print(context)
   
       def n_s():
           time.sleep(3000)
   
       t = PythonOperator(
           task_id="my_task",
           python_callable=n_s,
           on_failure_callback=fail_cb
       )
   
       t
   
   my_dag()
   
   ```
   
   
   DAG Processor Logs after I killed the Supervisor & task process when the 
task is running:
   
   ```
   {"timestamp":"2025-07-08T22:48:31.568171Z","level":"info","event":"{'dag': 
<DAG: my_dag>, 'inlets': [], 'map_index_template': None, 'outlets': [], 
'run_id': 'manual__2025-07-08T22:44:37.346022+00:00', 'task': 
<Task(PythonOperator): my_task>, 'task_instance': 
RuntimeTaskInstance(id=UUID('0197ec36-656a-75b7-814a-c409886945e2'), 
task_id='my_task', dag_id='my_dag', 
run_id='manual__2025-07-08T22:44:37.346022+00:00', try_number=2, 
dag_version_id=UUID('0197ec0c-669e-7e05-80e3-97c3549dbfda'), map_index=-1, 
hostname='c9bd6c415dbf', context_carrier={}, task=<Task(PythonOperator): 
my_task>, max_tries=0, end_date=None, state=None, is_mapped=None, 
rendered_map_index=None, log_url=None), 'ti': 
RuntimeTaskInstance(id=UUID('0197ec36-656a-75b7-814a-c409886945e2'), 
task_id='my_task', dag_id='my_dag', 
run_id='manual__2025-07-08T22:44:37.346022+00:00', try_number=2, 
dag_version_id=UUID('0197ec0c-669e-7e05-80e3-97c3549dbfda'), map_index=-1, 
hostname='c9bd6c415dbf', context_carrier={}, task=<Task(Pytho
 nOperator): my_task>, max_tries=0, end_date=None, state=None, is_mapped=None, 
rendered_map_index=None, log_url=None), 'outlet_events': 
<airflow.sdk.execution_time.context.OutletEventAccessors object at 
0xffff6cb48880>, 'inlet_events': InletEventsAccessors(_inlets=[], _assets={}, 
_asset_aliases={}), 'macros': <MacrosAccessor (dynamic access to macros)>, 
'params': {}, 'var': {'json': <VariableAccessor (dynamic access)>, 'value': 
<VariableAccessor (dynamic access)>}, 'conn': <ConnectionAccessor (dynamic 
access)>, 'dag_run': DagRun(dag_id='my_dag', 
run_id='manual__2025-07-08T22:44:37.346022+00:00', 
logical_date=datetime.datetime(2025, 7, 8, 22, 44, 35, 842000, 
tzinfo=Timezone('UTC')), data_interval_start=datetime.datetime(2025, 7, 8, 22, 
44, 35, 842000, tzinfo=Timezone('UTC')), 
data_interval_end=datetime.datetime(2025, 7, 8, 22, 44, 35, 842000, 
tzinfo=Timezone('UTC')), run_after=datetime.datetime(2025, 7, 8, 22, 44, 35, 
842000, tzinfo=Timezone('UTC')), start_date=datetime.datetime(2025,
  7, 8, 22, 44, 44, 227565, tzinfo=Timezone('UTC')), end_date=None, 
clear_number=0, run_type=<DagRunType.MANUAL: 'manual'>, conf={}, 
consumed_asset_events=[]), 'triggering_asset_events': 
TriggeringAssetEventsAccessor(_events=defaultdict(<class 'list'>, {})), 
'task_instance_key_str': 'my_dag__my_task__20250708', 'task_reschedule_count': 
0, 'prev_start_date_success': <Proxy at 0xffff6cb48cd0 with factory <function 
RuntimeTaskInstance.get_template_context.<locals>.<lambda> at 0xffff6c494280>>, 
'prev_end_date_success': <Proxy at 0xffff6cb48d30 with factory <function 
RuntimeTaskInstance.get_template_context.<locals>.<lambda> at 0xffff6c8e5120>>, 
'logical_date': DateTime(2025, 7, 8, 22, 44, 35, 842000, 
tzinfo=Timezone('UTC')), 'ds': '2025-07-08', 'ds_nodash': '20250708', 'ts': 
'2025-07-08T22:44:35.842000+00:00', 'ts_nodash': '20250708T224435', 
'ts_nodash_with_tz': '20250708T224435.842000+0000', 'data_interval_end': 
DateTime(2025, 7, 8, 22, 44, 35, 842000, tzinfo=Timezone('UTC')), 'data_int
 erval_start': DateTime(2025, 7, 8, 22, 44, 35, 842000, 
tzinfo=Timezone('UTC')), 'prev_data_interval_start_success': <Proxy at 
0xffff6cb48dc0 with factory <function 
RuntimeTaskInstance.get_template_context.<locals>.<lambda> at 0xffff6c8e51b0>>, 
'prev_data_interval_end_success': <Proxy at 0xffff6cb48df0 with factory 
<function RuntimeTaskInstance.get_template_context.<locals>.<lambda> at 
0xffff6c8e5240>>}","chan":"stdout","logger":"processor"}
   {"timestamp":"2025-07-08T22:48:31.568235Z","level":"info","event":"From 
inside the callback","chan":"stdout","logger":"processor"}
   {"timestamp":"2025-07-08T22:48:31.572041Z","level":"info","event":"{'dag': 
<DAG: my_dag>, 'inlets': [], 'map_index_template': None, 'outlets': [], 
'run_id': 'manual__2025-07-08T22:44:37.346022+00:00', 'task': 
<Task(PythonOperator): my_task>, 'task_instance': 
RuntimeTaskInstance(id=UUID('0197ec36-656a-75b7-814a-c409886945e2'), 
task_id='my_task', dag_id='my_dag', 
run_id='manual__2025-07-08T22:44:37.346022+00:00', try_number=2, 
dag_version_id=UUID('0197ec0c-669e-7e05-80e3-97c3549dbfda'), map_index=-1, 
hostname='c9bd6c415dbf', context_carrier={}, task=<Task(PythonOperator): 
my_task>, max_tries=0, end_date=None, state=None, is_mapped=None, 
rendered_map_index=None, log_url=None), 'ti': 
RuntimeTaskInstance(id=UUID('0197ec36-656a-75b7-814a-c409886945e2'), 
task_id='my_task', dag_id='my_dag', 
run_id='manual__2025-07-08T22:44:37.346022+00:00', try_number=2, 
dag_version_id=UUID('0197ec0c-669e-7e05-80e3-97c3549dbfda'), map_index=-1, 
hostname='c9bd6c415dbf', context_carrier={}, task=<Task(Pytho
 nOperator): my_task>, max_tries=0, end_date=None, state=None, is_mapped=None, 
rendered_map_index=None, log_url=None), 'outlet_events': 
<airflow.sdk.execution_time.context.OutletEventAccessors object at 
0xffff6cb48e20>, 'inlet_events': InletEventsAccessors(_inlets=[], _assets={}, 
_asset_aliases={}), 'macros': <MacrosAccessor (dynamic access to macros)>, 
'params': {}, 'var': {'json': <VariableAccessor (dynamic access)>, 'value': 
<VariableAccessor (dynamic access)>}, 'conn': <ConnectionAccessor (dynamic 
access)>, 'dag_run': DagRun(dag_id='my_dag', 
run_id='manual__2025-07-08T22:44:37.346022+00:00', 
logical_date=datetime.datetime(2025, 7, 8, 22, 44, 35, 842000, 
tzinfo=Timezone('UTC')), data_interval_start=datetime.datetime(2025, 7, 8, 22, 
44, 35, 842000, tzinfo=Timezone('UTC')), 
data_interval_end=datetime.datetime(2025, 7, 8, 22, 44, 35, 842000, 
tzinfo=Timezone('UTC')), run_after=datetime.datetime(2025, 7, 8, 22, 44, 35, 
842000, tzinfo=Timezone('UTC')), start_date=datetime.datetime(2025,
  7, 8, 22, 44, 44, 227565, tzinfo=Timezone('UTC')), end_date=None, 
clear_number=0, run_type=<DagRunType.MANUAL: 'manual'>, conf={}, 
consumed_asset_events=[]), 'triggering_asset_events': 
TriggeringAssetEventsAccessor(_events=defaultdict(<class 'list'>, {})), 
'task_instance_key_str': 'my_dag__my_task__20250708', 'task_reschedule_count': 
0, 'prev_start_date_success': <Proxy at 0xffff6cb48ca0 with factory <function 
RuntimeTaskInstance.get_template_context.<locals>.<lambda> at 0xffff6c494280>>, 
'prev_end_date_success': <Proxy at 0xffff6cb48c70 with factory <function 
RuntimeTaskInstance.get_template_context.<locals>.<lambda> at 0xffff6c8e52d0>>, 
'logical_date': DateTime(2025, 7, 8, 22, 44, 35, 842000, 
tzinfo=Timezone('UTC')), 'ds': '2025-07-08', 'ds_nodash': '20250708', 'ts': 
'2025-07-08T22:44:35.842000+00:00', 'ts_nodash': '20250708T224435', 
'ts_nodash_with_tz': '20250708T224435.842000+0000', 'data_interval_end': 
DateTime(2025, 7, 8, 22, 44, 35, 842000, tzinfo=Timezone('UTC')), 'data_int
 erval_start': DateTime(2025, 7, 8, 22, 44, 35, 842000, 
tzinfo=Timezone('UTC')), 'prev_data_interval_start_success': <Proxy at 
0xffff6cb488e0 with factory <function 
RuntimeTaskInstance.get_template_context.<locals>.<lambda> at 0xffff6c8e5240>>, 
'prev_data_interval_end_success': <Proxy at 0xffff6cb48880 with factory 
<function RuntimeTaskInstance.get_template_context.<locals>.<lambda> at 
0xffff6c8e51b0>>}","chan":"stdout","logger":"processor"}
   ```
   
   <!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
   
      http://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
    -->
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of an existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   
   
   <!-- Please keep an empty line above the dashes. -->
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request 
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
 for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal 
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
 is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party 
License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in a 
newsfragment file, named `{pr_number}.significant.rst` or 
`{issue_number}.significant.rst`, in 
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
   


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

Reply via email to