alexott commented on code in PR #27446:
URL: https://github.com/apache/airflow/pull/27446#discussion_r1012566172


##########
airflow/providers/databricks/hooks/databricks.py:
##########
@@ -171,22 +171,41 @@ def list_jobs(self, limit: int = 25, offset: int = 0, 
expand_tasks: bool = False
                 "expand_tasks": expand_tasks,
             }
             response = self._do_api_call(LIST_JOBS_ENDPOINT, json)
-            jobs += response["jobs"] if "jobs" in response else []
+            jobs += response.get("jobs", [])
             has_more = response.get("has_more", False)
             if has_more:
                 offset += len(response["jobs"])
 
         return jobs
 
-    def find_job_id_by_name(self, job_name: str) -> int | None:
+    def search_job(self, name: str, expand_tasks: bool = False) -> 
list[dict[str, Any]]:
+        """
+        Search for a named jobs in the Databricks Job Service.
+
+        :param name: The name of the job to search
+        :param expand_tasks: Whether to include task and cluster details in 
the response.
+        :return: A list of jobs with matching name
+        """
+        json = {
+            "name": name,
+            "expand_tasks": expand_tasks,
+        }
+        response = self._do_api_call(LIST_JOBS_ENDPOINT, json)
+        return response.get("jobs", [])
+
+    def find_job_id_by_name(self, job_name: str, use_old_list_impl: bool = 
False) -> int | None:
         """
         Finds job id by its name. If there are multiple jobs with the same 
name, raises AirflowException.
 
         :param job_name: The name of the job to look up.
+        :param use_old_list_impl: if we should use old implementation by using 
list all API.
         :return: The job_id as an int or None if no job was found.
         """
-        all_jobs = self.list_jobs()
-        matching_jobs = [j for j in all_jobs if j["settings"]["name"] == 
job_name]
+        if use_old_list_impl:  # For compatibility with old implementation

Review Comment:
   I'll reimplement it a different way - that's why I converted it to draft.



-- 
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]

Reply via email to