uranusjr commented on code in PR #68974:
URL: https://github.com/apache/airflow/pull/68974#discussion_r3493933833
##########
providers/databricks/src/airflow/providers/databricks/operators/databricks.py:
##########
@@ -877,6 +912,54 @@ def
_inject_openlineage_properties_into_databricks_job(self, json: dict, context
)
return json
+ def submit_job(self, context: Context) -> int:
+ normalised = self._prepare_submit_json(context)
+ # Set run_id the instant the run exists so on_kill can cancel it even
if the worker dies
+ # before polling begins.
+ self.run_id = self._hook.submit_run(normalised)
+ self.log.info("Run submitted with run_id: %s", self.run_id)
+ return self.run_id
+
+ def get_job_status(self, external_id: JsonValue, context: Context) -> str:
+ # Databricks splits run state across life_cycle_state and
result_state; the mixin's status
+ # interface is a single string, so encode both as "LIFE_CYCLE:RESULT"
and decode them in
+ # is_job_active / is_job_succeeded.
+ try:
+ run_info = self._hook.get_run(external_id)
+ except DatabricksApiError as e:
+ # A stored run whose history expired (or was deleted) returns 404.
Report a sentinel that
+ # is neither active nor succeeded so the mixin resubmits fresh
instead of failing the task.
+ if e.http_status_code == 404:
+ return "NOT_FOUND:"
+ raise
+ state = RunState(**run_info["state"])
+ return f"{state.life_cycle_state}:{state.result_state}"
+
+ def is_job_active(self, status: str) -> bool:
+ life_cycle_state = status.split(":", 1)[0]
+ return life_cycle_state not in ("TERMINATED", "SKIPPED",
"INTERNAL_ERROR", "NOT_FOUND")
Review Comment:
Probably better to use a positive list of states instead? It would be more
durable if Databricks adds more states in the future. (I have no idea if that’s
possible or likely.)
--
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]