collinmcnulty opened a new issue, #57210:
URL: https://github.com/apache/airflow/issues/57210

   ### Description
   
   Tasks that are coming out of deferred should dramatically increase their own 
priority_weight so that they show up at the top of this query and are at the 
front of the line for landing on a worker.
   
   ```
   query = (
                   select(TI)
                   .with_hint(TI, "USE INDEX (ti_state)", dialect_name="mysql")
                   .join(TI.dag_run)
                   .where(DR.state == DagRunState.RUNNING)
                   .join(TI.dag_model)
                   .where(~DM.is_paused)
                   .where(TI.state == TaskInstanceState.SCHEDULED)
                   .where(DM.bundle_name.is_not(None))
                   .options(selectinload(TI.dag_model))
                   .order_by(-TI.priority_weight, DR.logical_date, TI.map_index)
           )
   ```
   
   ### Use case/motivation
   
   When a task leaves deferred, it (in most cases) needs to go back to 
scheduled to get to a worker for execute_complete. In cases where the task's 
pool is full when it finishes, this can lead to long delays between when a 
task's main goal is finished and it actually completing. For instance, in KPO, 
this can lead to the pod not being around anymore by the time the 
execute_complete tries to read the final logs. 
   
   ### Related issues
   
   _No response_
   
   ### Are you willing to submit a PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


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