From 670ba51d9bd9a9a0b07a2ed064c316234bb5819d Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Fri, 21 Apr 2023 08:49:45 +0200 Subject: [PATCH] feat(backend): workers are instantly ready and sync with global cache in background --- backend/README.md | 9 +++- backend/sqlx-data.json | 12 +++++ backend/src/main.rs | 19 ++------ backend/windmill-worker/src/global_cache.rs | 34 ++++---------- backend/windmill-worker/src/lib.rs | 4 -- .../windmill-worker/src/python_executor.rs | 3 ++ backend/windmill-worker/src/worker.rs | 47 +++++++++++++++++-- 7 files changed, 78 insertions(+), 50 deletions(-) diff --git a/backend/README.md b/backend/README.md index 2d3d35b1a1..04d27762a2 100644 --- a/backend/README.md +++ b/backend/README.md @@ -1,6 +1,7 @@ # Windmill Backend -This folder holds all backend components, the [src/](./src/) folder only contains files used to build the "root" binary. +This folder holds all backend components, the [src/](./src/) folder only +contains files used to build the "root" binary. ## Components @@ -13,3 +14,9 @@ This folder holds all backend components, the [src/](./src/) folder only contain | [windmill-queue](./windmill-queue/) | Contains job & flow queuing functionality, commonly written to by the API server and read from by workers | | [windmill-worker](./windmill-worker/) | The worker. Used to process and execute flows & jobs. | | [parsers](./parsers/) | Contains code to parse signatures in different langauges. | + +### Compile sqlx for offline ci + +``` +cargo sqlx prepare --merged -- --bin windmill --features enterprise +``` diff --git a/backend/sqlx-data.json b/backend/sqlx-data.json index 66e32e4f0f..14ca54a791 100644 --- a/backend/sqlx-data.json +++ b/backend/sqlx-data.json @@ -238,6 +238,18 @@ }, "query": "SELECT script_path FROM queue WHERE id = $1" }, + "062859f1d0e5cfba3115f4241115753b86a4ad239708851c998ff5620ebca5b8": { + "describe": { + "columns": [], + "nullable": [], + "parameters": { + "Left": [ + "Uuid" + ] + } + }, + "query": "UPDATE queue SET last_ping = now() WHERE id = $1" + }, "0715955b7e98cc669a88eca6556cd46b7f9c07fcf32a24f85b69720b54e6e95f": { "describe": { "columns": [ diff --git a/backend/src/main.rs b/backend/src/main.rs index 411ccba489..ca0c81c4b0 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -8,7 +8,7 @@ use std::{ net::{IpAddr, Ipv4Addr, SocketAddr}, - sync::{atomic::Ordering, Arc}, + sync::Arc, }; use git_version::git_version; @@ -16,13 +16,12 @@ use monitor::handle_zombie_jobs_periodically; use sqlx::{Pool, Postgres}; use tokio::{ fs::{metadata, DirBuilder}, - join, sync::RwLock, }; -use windmill_common::{utils::rd_string, IS_READY, METRICS_ADDR}; +use windmill_common::{utils::rd_string, METRICS_ADDR}; use windmill_worker::{ DENO_CACHE_DIR, DENO_TMP_CACHE_DIR, GO_CACHE_DIR, GO_TMP_CACHE_DIR, PIP_CACHE_DIR, - ROOT_TMP_CACHE_DIR, S3_CACHE_BUCKET, TAR_PIP_TMP_CACHE_DIR, + ROOT_TMP_CACHE_DIR, TAR_PIP_TMP_CACHE_DIR, }; const GIT_VERSION: &str = git_version!(args = ["--tag", "--always"], fallback = "unknown-version"); @@ -299,18 +298,6 @@ pub async fn run_workers(5); let (job_completed_tx, mut job_completed_rx) = mpsc::channel::(10); @@ -515,16 +543,23 @@ pub async fn run_worker { + #[cfg(feature = "enterprise")] if let Some(copy_cache_from_bucket_handle) = copy_cache_from_bucket_handle.as_ref() { if !copy_cache_from_bucket_handle.is_finished() { copy_cache_from_bucket_handle.abort(); } } + #[cfg(feature = "enterprise")] + for handle in &handles { + if !handle.is_finished() { + handle.abort(); + } + } println!("received killpill for worker {}", i_worker); (true, Ok(None)) }, _ = copy_to_bucket_rx.recv() => { - tracing::debug!("CAN PULL LOCK START"); + tracing::debug!("can_pull lock start"); let _lock = CAN_PULL.write().await; if num_workers > 1 { create_barrier_for_all_workers(num_workers, sync_barrier.clone()).await; @@ -534,7 +569,7 @@ pub async fn run_worker { @@ -559,6 +594,8 @@ pub async fn run_worker