nradz commented on issue #45529:
URL: https://github.com/apache/airflow/issues/45529#issuecomment-2590097952
Hello! I has also experimented this issue and I has fixed it with the
following code, if it could help in the PR. I try to maintain the
"cached_property", assuming that load the executors is costly. Also, I don't
know if _init_executors_ is the most "elegant" way to retrieve the executors,
but it is the only function that I have found to do it.
```python
def _executor_get_task_log(self, ti: TaskInstance, try_number: int)
-> tuple[list[str], list[str]]:
"""
Get logs from executor.
:param ti: task instance object
:param try_number: task instance try_number to read logs from
:return: a tuple of messages and logs
"""
executor_name = ti.executor
if executor_name is None:
executor = list(self._available_executors.values())[0]
elif executor_name in self._available_executors:
executor = self._available_executors[executor_name]
else:
raise AirflowException(f"Executor {executor_name} not found
for task {ti}")
return executor.get_task_log(ti, try_number)
@cached_property
def _available_executors(self) -> Dict[str, BaseExecutor]:
"""This cached property avoids loading executors repeatedly."""
return {
ex.__class__.__name__: ex
for ex in ExecutorLoader.init_executors()
}
```
--
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]