Skip to content

Commit 804507e

Browse files
refactor: extract job execution logic into _run_job method
1 parent b510e35 commit 804507e

File tree

1 file changed

+45
-36
lines changed

1 file changed

+45
-36
lines changed

src/databricks/labs/lakebridge/transpiler/switch_runner.py

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -83,42 +83,7 @@ def run(
8383
)
8484
logger.info(f"Triggering Switch job with job_id: {job_id}")
8585

86-
if wait_for_completion:
87-
run = self._ws.jobs.run_now_and_wait(job_id, notebook_params=job_params)
88-
89-
if not run.run_id:
90-
raise SystemExit(f"Job {job_id} execution failed.")
91-
92-
job_run_url = f"{self._ws.config.host}/jobs/{job_id}/runs/{run.run_id}"
93-
logger.info(f"Switch LLM transpilation job completed: {job_run_url}")
94-
95-
return [
96-
{
97-
"job_id": job_id,
98-
"run_id": run.run_id,
99-
"run_url": job_run_url,
100-
"state": (
101-
run.state.life_cycle_state.value if run.state and run.state.life_cycle_state else "UNKNOWN"
102-
),
103-
"result_state": run.state.result_state.value if run.state and run.state.result_state else None,
104-
}
105-
]
106-
107-
wait = self._ws.jobs.run_now(job_id, notebook_params=job_params)
108-
109-
if not wait.run_id:
110-
raise SystemExit(f"Job {job_id} execution failed.")
111-
112-
job_run_url = f"{self._ws.config.host}/jobs/{job_id}/runs/{wait.run_id}"
113-
logger.info(f"Switch LLM transpilation job started: {job_run_url}")
114-
115-
return [
116-
{
117-
"job_id": job_id,
118-
"run_id": wait.run_id,
119-
"run_url": job_run_url,
120-
}
121-
]
86+
return self._run_job(job_id, job_params, wait_for_completion)
12287

12388
def _upload_to_volume(
12489
self,
@@ -180,3 +145,47 @@ def _build_job_parameters(
180145
"builtin_prompt": source_dialect,
181146
**switch_options,
182147
}
148+
149+
def _run_job(
150+
self,
151+
job_id: int,
152+
job_params: dict[str, str],
153+
wait_for_completion: bool,
154+
) -> RootJsonValue:
155+
"""Execute Switch job and return run information."""
156+
if wait_for_completion:
157+
run = self._ws.jobs.run_now_and_wait(job_id, notebook_params=job_params)
158+
159+
if not run.run_id:
160+
raise SystemExit(f"Job {job_id} execution failed.")
161+
162+
job_run_url = f"{self._ws.config.host}/jobs/{job_id}/runs/{run.run_id}"
163+
logger.info(f"Switch LLM transpilation job completed: {job_run_url}")
164+
165+
return [
166+
{
167+
"job_id": job_id,
168+
"run_id": run.run_id,
169+
"run_url": job_run_url,
170+
"state": (
171+
run.state.life_cycle_state.value if run.state and run.state.life_cycle_state else "UNKNOWN"
172+
),
173+
"result_state": run.state.result_state.value if run.state and run.state.result_state else None,
174+
}
175+
]
176+
177+
wait = self._ws.jobs.run_now(job_id, notebook_params=job_params)
178+
179+
if not wait.run_id:
180+
raise SystemExit(f"Job {job_id} execution failed.")
181+
182+
job_run_url = f"{self._ws.config.host}/jobs/{job_id}/runs/{wait.run_id}"
183+
logger.info(f"Switch LLM transpilation job started: {job_run_url}")
184+
185+
return [
186+
{
187+
"job_id": job_id,
188+
"run_id": wait.run_id,
189+
"run_url": job_run_url,
190+
}
191+
]

0 commit comments

Comments
 (0)