Skip to content

Commit

Permalink
nit fix hub cache init on server
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfiszel committed Feb 1, 2025
1 parent f9e4e0a commit 0c4901f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
20 changes: 8 additions & 12 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ use rand::Rng;
use sqlx::{postgres::PgListener, Pool, Postgres};
use std::{
collections::HashMap,
fs::{create_dir_all, DirBuilder},
net::{IpAddr, Ipv4Addr, SocketAddr},
time::Duration,
};
use tokio::{
fs::{create_dir_all, DirBuilder, File},
io::AsyncReadExt,
};
use tokio::{fs::File, io::AsyncReadExt};
use uuid::Uuid;
use windmill_api::HTTP_CLIENT;

Expand All @@ -47,7 +45,7 @@ use windmill_common::{
scripts::ScriptLang,
stats_ee::schedule_stats,
utils::{hostname, rd_string, Mode, GIT_VERSION},
worker::{reload_custom_tags_setting, HUB_CACHE_DIR, TMP_DIR, WORKER_GROUP},
worker::{reload_custom_tags_setting, HUB_CACHE_DIR, TMP_DIR, TMP_LOGS_DIR, WORKER_GROUP},
DB, METRICS_ENABLED,
};

Expand All @@ -73,7 +71,7 @@ use windmill_worker::{
DENO_CACHE_DIR_NPM, GO_BIN_CACHE_DIR, GO_CACHE_DIR, LOCK_CACHE_DIR, PIP_CACHE_DIR,
POWERSHELL_CACHE_DIR, PY310_CACHE_DIR, PY311_CACHE_DIR, PY312_CACHE_DIR, PY313_CACHE_DIR,
RUST_CACHE_DIR, TAR_PIP_CACHE_DIR, TAR_PY310_CACHE_DIR, TAR_PY311_CACHE_DIR,
TAR_PY312_CACHE_DIR, TAR_PY313_CACHE_DIR, TMP_LOGS_DIR, UV_CACHE_DIR,
TAR_PY312_CACHE_DIR, TAR_PY313_CACHE_DIR, UV_CACHE_DIR,
};

use crate::monitor::{
Expand Down Expand Up @@ -140,8 +138,8 @@ async fn cache_hub_scripts(file_path: Option<String>) -> anyhow::Result<()> {
)
})?;

create_dir_all(HUB_CACHE_DIR).await?;
create_dir_all(BUN_BUNDLE_CACHE_DIR).await?;
create_dir_all(HUB_CACHE_DIR)?;
create_dir_all(BUN_BUNDLE_CACHE_DIR)?;

for path in paths.values() {
tracing::info!("Caching hub script at {path}");
Expand All @@ -152,7 +150,7 @@ async fn cache_hub_scripts(file_path: Option<String>) -> anyhow::Result<()> {
.is_some_and(|x| x == &ScriptLang::Deno)
{
let job_dir = format!("{}/cache_init/{}", TMP_DIR, Uuid::new_v4());
create_dir_all(&job_dir).await?;
create_dir_all(&job_dir)?;
let _ = windmill_worker::generate_deno_lock(
&Uuid::nil(),
&res.content,
Expand All @@ -170,7 +168,7 @@ async fn cache_hub_scripts(file_path: Option<String>) -> anyhow::Result<()> {
} else if res.language.as_ref().is_some_and(|x| x == &ScriptLang::Bun) {
let job_id = Uuid::new_v4();
let job_dir = format!("{}/cache_init/{}", TMP_DIR, job_id);
create_dir_all(&job_dir).await?;
create_dir_all(&job_dir)?;
if let Some(lockfile) = res.lockfile {
let _ = windmill_worker::prepare_job_dir(&lockfile, &job_dir).await?;
let envs = windmill_worker::get_common_bun_proc_envs(None).await;
Expand Down Expand Up @@ -505,7 +503,6 @@ Windmill Community Edition {GIT_VERSION}
DirBuilder::new()
.recursive(true)
.create("/tmp/windmill")
.await
.expect("could not create initial server dir");

#[cfg(feature = "tantivy")]
Expand Down Expand Up @@ -1047,7 +1044,6 @@ pub async fn run_workers(
DirBuilder::new()
.recursive(true)
.create(x)
.await
.expect("could not create initial worker dir");
}

Expand Down
9 changes: 9 additions & 0 deletions backend/windmill-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ use http::HeaderValue;
use reqwest::Client;
#[cfg(feature = "oauth2")]
use std::collections::HashMap;
use windmill_common::worker::HUB_CACHE_DIR;

use std::fs::DirBuilder;
use std::time::Duration;
use std::{net::SocketAddr, sync::Arc};
use tokio::sync::RwLock;
Expand Down Expand Up @@ -203,6 +205,13 @@ pub async fn run_server(
) -> anyhow::Result<()> {
let user_db = UserDB::new(db.clone());

for x in [HUB_CACHE_DIR] {
DirBuilder::new()
.recursive(true)
.create(x)
.expect("could not create initial server dir");
}

#[cfg(feature = "enterprise")]
let ext_jwks = ExternalJwks::load().await;
let auth_cache = Arc::new(crate::auth::AuthCache::new(
Expand Down
2 changes: 2 additions & 0 deletions backend/windmill-common/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ pub async fn make_pull_query(wc: &WorkerConfig) {
}

pub const TMP_DIR: &str = "/tmp/windmill";
pub const TMP_LOGS_DIR: &str = concatcp!(TMP_DIR, "/logs");

pub const HUB_CACHE_DIR: &str = concatcp!(ROOT_CACHE_DIR, "hub");

pub const ROOT_CACHE_DIR: &str = concatcp!(TMP_DIR, "/cache/");
Expand Down
2 changes: 0 additions & 2 deletions backend/windmill-worker/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,6 @@ pub async fn create_token_for_owner(
Ok(format!("jwt_{}", token))
}

pub const TMP_LOGS_DIR: &str = concatcp!(TMP_DIR, "/logs");

pub const ROOT_CACHE_NOMOUNT_DIR: &str = concatcp!(TMP_DIR, "/cache_nomount/");

pub const LOCK_CACHE_DIR: &str = concatcp!(ROOT_CACHE_DIR, "lock");
Expand Down

0 comments on commit 0c4901f

Please sign in to comment.