Skip to content

Commit c4ec304

Browse files
committed
Preinstall latest stable in non-blocking manner
1 parent 05ba8bf commit c4ec304

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

backend/windmill-worker/src/python_executor.rs

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,12 @@ impl PyVersion {
157157
"3.11" => Some(Py311),
158158
"3.12" => Some(Py312),
159159
"3.13" => Some(Py313),
160-
_ => None,
160+
_ => {
161+
tracing::warn!(
162+
"Cannot convert string (\"{value}\") to PyVersion\nExpected format x.yz"
163+
);
164+
None
165+
}
161166
}
162167
}
163168
pub fn from_string_no_dots(value: &str) -> Option<Self> {
@@ -168,7 +173,9 @@ impl PyVersion {
168173
"312" => Some(Py312),
169174
"313" => Some(Py313),
170175
_ => {
171-
tracing::warn!("Cannot convert string (\"{value}\") to PyVersion");
176+
tracing::warn!(
177+
"Cannot convert string (\"{value}\") to PyVersion\nExpected format xyz"
178+
);
172179
None
173180
}
174181
}
@@ -212,7 +219,6 @@ impl PyVersion {
212219
}
213220
}
214221
pub async fn install_python(
215-
job_dir: &str,
216222
job_id: &Uuid,
217223
mem_peak: &mut i32,
218224
// canceled_by: &mut Option<CanceledBy>,
@@ -225,7 +231,7 @@ impl PyVersion {
225231
append_logs(
226232
job_id,
227233
w_id,
228-
format!("\n\n--- INSTALLING PYTHON ({}) ---\n", version),
234+
format!("\n\nINSTALLING PYTHON ({})", version),
229235
db,
230236
)
231237
.await;
@@ -248,7 +254,6 @@ impl PyVersion {
248254
// let v_with_dot = self.to_string_with_dot();
249255
let mut child_cmd = Command::new(UV_PATH.as_str());
250256
child_cmd
251-
.current_dir(job_dir)
252257
.args([
253258
"python",
254259
"install",
@@ -280,7 +285,6 @@ impl PyVersion {
280285
.await
281286
}
282287
async fn get_python_inner(
283-
job_dir: &str,
284288
job_id: &Uuid,
285289
mem_peak: &mut i32,
286290
// canceled_by: &mut Option<CanceledBy>,
@@ -290,13 +294,12 @@ impl PyVersion {
290294
occupancy_metrics: &mut Option<&mut OccupancyMetrics>,
291295
version: &str,
292296
) -> error::Result<Option<String>> {
293-
let py_path = Self::find_python(job_dir, version).await;
297+
let py_path = Self::find_python(version).await;
294298

295-
// Python is not installed
299+
// Runtime is not installed
296300
if py_path.is_err() {
297301
// Install it
298302
if let Err(err) = Self::install_python(
299-
job_dir,
300303
job_id,
301304
mem_peak,
302305
db,
@@ -311,7 +314,7 @@ impl PyVersion {
311314
return Err(err);
312315
} else {
313316
// Try to find one more time
314-
let py_path = Self::find_python(job_dir, version).await;
317+
let py_path = Self::find_python(version).await;
315318

316319
if let Err(err) = py_path {
317320
tracing::error!("Cannot find python version {err}");
@@ -327,7 +330,6 @@ impl PyVersion {
327330
}
328331
pub async fn get_python(
329332
&self,
330-
job_dir: &str,
331333
job_id: &Uuid,
332334
mem_peak: &mut i32,
333335
// canceled_by: &mut Option<CanceledBy>,
@@ -341,7 +343,6 @@ impl PyVersion {
341343
// }
342344

343345
let res = Self::get_python_inner(
344-
job_dir,
345346
job_id,
346347
mem_peak,
347348
db,
@@ -360,12 +361,12 @@ impl PyVersion {
360361
}
361362
res
362363
}
363-
async fn find_python(job_dir: &str, version: &str) -> error::Result<Option<String>> {
364+
async fn find_python(version: &str) -> error::Result<Option<String>> {
364365
// let mut logs = String::new();
365366
// let v_with_dot = self.to_string_with_dot();
366367
let mut child_cmd = Command::new(UV_PATH.as_str());
367368
let output = child_cmd
368-
.current_dir(job_dir)
369+
// .current_dir(job_dir)
369370
.args([
370371
"python",
371372
"find",
@@ -880,7 +881,6 @@ pub async fn handle_python_job(
880881
PYTHON_PATH.clone()
881882
} else if let Some(python_path) = py_version
882883
.get_python(
883-
job_dir,
884884
&job.id,
885885
mem_peak,
886886
db,
@@ -2085,15 +2085,7 @@ pub async fn handle_python_reqs(
20852085
None
20862086
} else {
20872087
py_version
2088-
.get_python(
2089-
&job_dir,
2090-
job_id,
2091-
mem_peak,
2092-
db,
2093-
_worker_name,
2094-
w_id,
2095-
_occupancy_metrics,
2096-
)
2088+
.get_python(job_id, mem_peak, db, _worker_name, w_id, _occupancy_metrics)
20972089
.await?
20982090
};
20992091

backend/windmill-worker/src/worker.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ use tokio::fs::symlink;
7979
use tokio::fs::symlink_file as symlink;
8080

8181
use tokio::{
82+
spawn,
8283
sync::{
8384
mpsc::{self, Sender},
8485
RwLock,
@@ -777,17 +778,27 @@ pub async fn run_worker(
777778
let worker_dir = format!("{TMP_DIR}/{worker_name}");
778779
tracing::debug!(worker = %worker_name, hostname = %hostname, worker_dir = %worker_dir, "Creating worker dir");
779780

780-
if let Err(e) = PyVersion::from_instance_version()
781-
.await
782-
.get_python("", &Uuid::nil(), &mut 0, db, &worker_name, "", &mut None)
783-
.await
784781
{
785-
tracing::error!(
786-
worker = %worker_name,
787-
hostname = %hostname,
788-
worker_dir = %worker_dir,
789-
"Cannot install/find Instance Python version to worker: {e}"//
782+
let (db, worker_name, hostname, worker_dir) = (
783+
db.clone(),
784+
worker_name.clone(),
785+
hostname.to_owned(),
786+
worker_dir.clone(),
790787
);
788+
spawn(async move {
789+
if let Err(e) = PyVersion::from_instance_version()
790+
.await
791+
.get_python(&Uuid::nil(), &mut 0, &db, &worker_name, "", &mut None)
792+
.await
793+
{
794+
tracing::error!(
795+
worker = %worker_name,
796+
hostname = %hostname,
797+
worker_dir = %worker_dir,
798+
"Cannot preinstall or find Instance Python version to worker: {e}"//
799+
);
800+
}
801+
});
791802
}
792803

793804
if let Some(ref netrc) = *NETRC {

0 commit comments

Comments
 (0)