jason810496 commented on code in PR #50192:
URL: https://github.com/apache/airflow/pull/50192#discussion_r2111938013
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/utils/pod_manager.py:
##########
@@ -377,7 +379,21 @@ def create_pod(self, pod: V1Pod) -> V1Pod:
"""Launch the pod asynchronously."""
return self.run_pod_async(pod)
- def await_pod_start(
+ async def watch_pod_events(self, pod: V1Pod, check_interval: int = 1) ->
None:
+ """Read pod events and writes into log."""
+ self.keep_watching_for_events = True
+ num_events = 0
+ while self.keep_watching_for_events:
+ events = self.read_pod_events(pod)
+ for new_event in events.items[num_events:]:
+ involved_object: V1ObjectReference = new_event.involved_object
+ self.log.info(
+ "The Pod has an Event: %s from %s", new_event.message,
involved_object.field_path
+ )
+ num_events = len(events.items)
+ await asyncio.sleep(check_interval)
+
+ async def await_pod_start(
Review Comment:
How about make the `await_pod_start` method still normal function instead of
async function?
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py:
##########
@@ -579,12 +580,20 @@ def get_or_create_pod(self, pod_request_obj: k8s.V1Pod,
context: Context) -> k8s
def await_pod_start(self, pod: k8s.V1Pod) -> None:
try:
- self.pod_manager.await_pod_start(
- pod=pod,
- schedule_timeout=self.schedule_timeout_seconds,
- startup_timeout=self.startup_timeout_seconds,
- check_interval=self.startup_check_interval_seconds,
+ loop = asyncio.get_event_loop()
+ events_task = asyncio.ensure_future(
+ self.pod_manager.watch_pod_events(pod,
self.startup_check_interval_seconds)
+ )
+ loop.run_until_complete(
+ self.pod_manager.await_pod_start(
Review Comment:
Then we could still use original `pod_manager.await_pod_start` with
`sync_to_async` (`from asgiref.sync import sync_to_async`) with `asyncio`.
--
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]