pankajkoti commented on code in PR #37363:
URL: https://github.com/apache/airflow/pull/37363#discussion_r1487388263
##########
airflow/providers/cncf/kubernetes/triggers/pod.py:
##########
@@ -155,18 +155,32 @@ def serialize(self) -> tuple[str, dict[str, Any]]:
},
)
+ def _get_terminal_event(self, state) -> TriggerEvent:
+ if state == PodPhase.SUCCEEDED:
+ status = "success"
+ else:
+ status = "failed"
+ return TriggerEvent({"status": status, "namespace":
self.pod_namespace, "name": self.pod_name})
+
async def run(self) -> AsyncIterator[TriggerEvent]: # type:
ignore[override]
"""Get current pod status and yield a TriggerEvent."""
self.log.info("Checking pod %r in namespace %r.", self.pod_name,
self.pod_namespace)
try:
state = await self._wait_for_pod_start()
if state in PodPhase.terminal_states:
- event = TriggerEvent(
- {"status": "done", "namespace": self.pod_namespace,
"pod_name": self.pod_name}
- )
+ event = self._get_terminal_event(state)
else:
event = await self._wait_for_container_completion()
yield event
+ except PodLaunchTimeoutException as e:
+ description = self._format_exception_description(e)
+ yield TriggerEvent(
+ {
+ "status": "timeout",
+ "error_type": e.__class__.__name__,
+ "description": description,
+ }
+ )
except Exception as e:
Review Comment:
Do we also need to catch a CancelledError?
Previously we had
```
except CancelledError:
# That means that task was marked as failed
if self.get_logs:
self.log.info("Outputting container logs...")
await self.hook.read_logs(
name=self.pod_name,
namespace=self.pod_namespace,
)
if self.on_finish_action == OnFinishAction.DELETE_POD:
self.log.info("Deleting pod...")
await self.hook.delete_pod(
name=self.pod_name,
namespace=self.pod_namespace,
)
yield TriggerEvent(
{
"name": self.pod_name,
"namespace": self.pod_namespace,
"status": "cancelled",
"message": "Pod execution was cancelled",
}
)
```
--
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]