simplify logic to check for license key on workers

This commit is contained in:
Ruben Fiszel
2024-11-27 18:50:59 +01:00
parent 4f83684ed6
commit 66fdd8723f
3 changed files with 26 additions and 24 deletions
+1 -16
View File
@@ -416,7 +416,7 @@ Windmill Community Edition {GIT_VERSION}
}
let valid_key = *LICENSE_KEY_VALID.read().await;
if !valid_key && !server_mode {
panic!("Invalid license key, workers require a valid license key");
tracing::error!("Invalid license key, workers require a valid license key");
}
if server_mode {
// only force renewal if invalid but not empty (= expired)
@@ -431,13 +431,6 @@ Windmill Community Edition {GIT_VERSION}
tracing::error!("Failed to reload license key: {err:#}");
}
}
if num_workers > 0 {
let valid_key = *LICENSE_KEY_VALID.read().await;
if !valid_key {
tracing::warn!("License key invalid, setting num_workers to 0");
num_workers = 0;
}
}
}
}
@@ -684,14 +677,6 @@ Windmill Community Edition {GIT_VERSION}
if let Err(e) = reload_license_key(&db).await {
tracing::error!("Failed to reload license key: {e:#}");
}
#[cfg(feature = "enterprise")]
if worker_mode {
let valid_key = *LICENSE_KEY_VALID.read().await;
if !valid_key {
tracing::error!("Invalid license key, exiting...");
tx.send(()).expect("send");
}
}
},
DEFAULT_TAGS_PER_WORKSPACE_SETTING => {
if let Err(e) = load_tag_per_workspace_enabled(&db).await {
-7
View File
@@ -1054,13 +1054,6 @@ pub async fn monitor_db(
#[cfg(feature = "enterprise")]
if !initial_load {
verify_license_key().await;
if _worker_mode {
let valid_key = *LICENSE_KEY_VALID.read().await;
if !valid_key {
tracing::error!("Invalid license key, exiting...");
_killpill_tx.send(()).expect("send");
}
}
}
};
+25 -1
View File
@@ -8,6 +8,7 @@
use windmill_common::{
auth::{fetch_authed_from_permissioned_as, JWTAuthClaims, JobPerms, JWT_SECRET},
ee::LICENSE_KEY_VALID,
scripts::PREVIEW_IS_TAR_CODEBASE_HASH,
worker::{
get_memory, get_vcpus, get_windmill_memory_usage, get_worker_memory_usage, write_file,
@@ -1072,6 +1073,28 @@ pub async fn run_worker(
let mut killed_but_draining_same_worker_jobs = false;
loop {
#[cfg(feature = "enterprise")]
{
if let Ok(_) = killpill_rx.try_recv() {
tracing::info!("killpill received on worker waiting for valid key");
job_completed_tx
.0
.send(SendResult::Kill)
.await
.expect("send kill to job completed tx");
break;
}
let valid_key = *LICENSE_KEY_VALID.read().await;
if !valid_key {
tracing::error!(
"Invalid license key, workers require a valid license key, sleeping for 30s waiting for valid key to be set"
);
tokio::time::sleep(Duration::from_secs(10)).await;
continue;
}
}
#[cfg(feature = "benchmark")]
let mut bench = BenchmarkIter::new();
@@ -1635,6 +1658,7 @@ pub async fn run_worker(
drop(job_completed_tx);
tracing::info!("waiting for job_completed_processor to finish processing remaining jobs");
if let Err(e) = send_result.await {
tracing::error!("error in awaiting send_result process: {e:?}")
}
@@ -2293,7 +2317,7 @@ async fn handle_code_execution_job(
envs: None,
codebase: None,
}
},
}
JobKind::DeploymentCallback => {
get_script_content_by_path(job.script_path.clone(), &job.workspace_id, db).await?
}