You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "moiseenkov (via GitHub)" <gi...@apache.org> on 2024/03/25 10:53:41 UTC
[PR] Implement deferrable mode for GKEStartJobOperator [airflow]
moiseenkov opened a new pull request, #38454:
URL: https://github.com/apache/airflow/pull/38454
Deferrable mode for `GKEStartJobOperator`
--
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-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Implement deferrable mode for GKEStartJobOperator [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #38454:
URL: https://github.com/apache/airflow/pull/38454#discussion_r1538521679
##########
airflow/providers/google/cloud/triggers/kubernetes_engine.py:
##########
@@ -237,3 +243,67 @@ def _get_hook(self) -> GKEAsyncHook:
impersonation_chain=self.impersonation_chain,
)
return self._hook
+
+
+class GKEJobTrigger(BaseTrigger):
+ """GKEJobTrigger run on the trigger worker to check the state of Job."""
+
+ def __init__(
+ self,
+ cluster_url: str,
+ ssl_ca_cert: str,
+ job_name: str,
+ job_namespace: str,
+ gcp_conn_id: str = "google_cloud_default",
+ poll_interval: float = 2,
+ impersonation_chain: str | Sequence[str] | None = None,
+ ):
Review Comment:
```suggestion
) -> None:
```
##########
airflow/providers/google/cloud/triggers/kubernetes_engine.py:
##########
@@ -237,3 +243,67 @@ def _get_hook(self) -> GKEAsyncHook:
impersonation_chain=self.impersonation_chain,
)
return self._hook
+
+
+class GKEJobTrigger(BaseTrigger):
+ """GKEJobTrigger run on the trigger worker to check the state of Job."""
+
+ def __init__(
+ self,
+ cluster_url: str,
+ ssl_ca_cert: str,
+ job_name: str,
+ job_namespace: str,
+ gcp_conn_id: str = "google_cloud_default",
+ poll_interval: float = 2,
+ impersonation_chain: str | Sequence[str] | None = None,
+ ):
+ super().__init__()
+ self.cluster_url = cluster_url
+ self.ssl_ca_cert = ssl_ca_cert
+ self.job_name = job_name
+ self.job_namespace = job_namespace
+ self.gcp_conn_id = gcp_conn_id
+ self.poll_interval = poll_interval
+ self.impersonation_chain = impersonation_chain
+
+ def serialize(self) -> tuple[str, dict[str, Any]]:
+ """Serialize KubernetesCreateJobTrigger arguments and classpath."""
+ return (
+ "airflow.providers.google.cloud.triggers.kubernetes_engine.GKEJobTrigger",
+ {
+ "cluster_url": self.cluster_url,
+ "ssl_ca_cert": self.ssl_ca_cert,
+ "job_name": self.job_name,
+ "job_namespace": self.job_namespace,
+ "gcp_conn_id": self.gcp_conn_id,
+ "poll_interval": self.poll_interval,
+ "impersonation_chain": self.impersonation_chain,
+ },
+ )
+
+ async def run(self) -> AsyncIterator[TriggerEvent]: # type: ignore[override]
+ """Get current job status and yield a TriggerEvent."""
+ job: V1Job = await self.hook.wait_until_job_complete(name=self.job_name, namespace=self.job_namespace)
+ job_dict = job.to_dict()
+ error_message = self.hook.is_job_failed(job=job)
+ yield TriggerEvent(
+ {
+ "name": job.metadata.name,
+ "namespace": job.metadata.namespace,
+ "status": "error" if error_message else "success",
+ "message": f"Job failed with error: {error_message}"
+ if error_message
+ else "Job completed successfully",
+ "job": job_dict,
+ }
+ )
Review Comment:
```suggestion
status = "error" if error_message else "success"
message = f"Job failed with error: {error_message}" if error_message else "Job completed successfully"
yield TriggerEvent(
{
"name": job.metadata.name,
"namespace": job.metadata.namespace,
"status": status
"message": message,
"job": job_dict,
}
)
```
I would suggest we move the if-else block out of the dict for better readbility
##########
tests/providers/google/cloud/triggers/test_kubernetes_engine.py:
##########
@@ -54,7 +61,7 @@
LOCATION = "us-central1-c"
GCP_CONN_ID = "test-non-existing-project-id"
IMPERSONATION_CHAIN = ["impersonate", "this", "test"]
-TRIGGER_PATH = "airflow.providers.google.cloud.triggers.kubernetes_engine.GKEOperationTrigger"
+TRIGGER_PATH = GKE_TRIGGERS_PATH + ".GKEOperationTrigger"
Review Comment:
```suggestion
TRIGGER_PATH = f"{GKE_TRIGGERS_PATH}.GKEOperationTrigger"
```
--
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-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Implement deferrable mode for GKEStartJobOperator [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk merged PR #38454:
URL: https://github.com/apache/airflow/pull/38454
--
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-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org