fix: change cache implementation to remove async-timer

This commit is contained in:
Ruben Fiszel
2023-09-23 08:33:49 +02:00
parent 51255981fa
commit e3edf4fa2a
5 changed files with 29 additions and 48 deletions
+20 -31
View File
@@ -392,17 +392,6 @@ version = "4.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae"
[[package]]
name = "async-timer"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba5fa6ed76cb2aa820707b4eb9ec46f42da9ce70b0eafab5e5e34942b38a44d5"
dependencies = [
"libc",
"wasm-bindgen",
"winapi",
]
[[package]]
name = "async-trait"
version = "0.1.73"
@@ -4096,6 +4085,18 @@ dependencies = [
"serde",
]
[[package]]
name = "quick_cache"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f69f8d22fa3f34f3083d9a4375c038732c7a7e964de1beb81c544da92dfc40b8"
dependencies = [
"ahash 0.8.3",
"equivalent",
"hashbrown 0.14.0",
"parking_lot",
]
[[package]]
name = "quote"
version = "1.0.33"
@@ -4348,18 +4349,6 @@ dependencies = [
"winreg",
]
[[package]]
name = "retainer"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df8c01a8276c14d0f8d51ebcf8a48f0748f9f73f5f6b29e688126e6a52bcb145"
dependencies = [
"async-lock",
"async-timer",
"log",
"rand 0.8.5",
]
[[package]]
name = "ring"
version = "0.16.20"
@@ -7137,16 +7126,16 @@ dependencies = [
"hex",
"hmac",
"hyper",
"itertools 0.10.5",
"itertools 0.11.0",
"lazy_static",
"magic-crypt",
"mail-send",
"mime_guess",
"prometheus",
"quick_cache",
"rand 0.8.5",
"regex",
"reqwest",
"retainer",
"rsa 0.7.2",
"rsmq_async",
"rust-embed",
@@ -7216,7 +7205,7 @@ dependencies = [
"hex",
"hmac",
"hyper",
"itertools 0.10.5",
"itertools 0.11.0",
"lazy_static",
"prometheus",
"rand 0.8.5",
@@ -7259,7 +7248,7 @@ version = "1.175.0"
dependencies = [
"anyhow",
"gosyn",
"itertools 0.10.5",
"itertools 0.11.0",
"lazy_static",
"regex",
"windmill-parser",
@@ -7281,7 +7270,7 @@ name = "windmill-parser-py"
version = "1.175.0"
dependencies = [
"anyhow",
"itertools 0.10.5",
"itertools 0.11.0",
"rustpython-parser",
"serde_json",
"windmill-parser",
@@ -7293,7 +7282,7 @@ version = "1.175.0"
dependencies = [
"anyhow",
"async-recursion",
"itertools 0.10.5",
"itertools 0.11.0",
"lazy_static",
"phf 0.11.2",
"regex",
@@ -7363,7 +7352,7 @@ dependencies = [
"futures-core",
"hex",
"hmac",
"itertools 0.10.5",
"itertools 0.11.0",
"lazy_static",
"prometheus",
"reqwest",
@@ -7401,7 +7390,7 @@ dependencies = [
"futures",
"gcp_auth",
"git-version",
"itertools 0.10.5",
"itertools 0.11.0",
"jsonwebtoken",
"lazy_static",
"mysql_async",
+1 -1
View File
@@ -113,7 +113,7 @@ mime_guess = "^2"
hex = "^0"
sql-builder = "^3"
argon2 = "^0"
retainer = "^0"
quick_cache = "^0"
rand = "0.8.5"
rand_core = { version = "^0", features = ["std"] }
magic-crypt = "^3"
+1 -1
View File
@@ -53,7 +53,7 @@ cron.workspace = true
mime_guess.workspace = true
rust-embed.workspace = true
tracing-subscriber.workspace = true
retainer.workspace = true
quick_cache.workspace = true
rand.workspace = true
time.workspace = true
magic-crypt.workspace = true
-2
View File
@@ -271,8 +271,6 @@ pub async fn run_server(
println!("Graceful shutdown of server");
});
tokio::spawn(async move { auth_cache.monitor().await });
server.await?;
Ok(())
}
+7 -13
View File
@@ -1,7 +1,8 @@
use std::time::Duration;
use quick_cache::sync::Cache;
use serde::Serialize;
use tokio::{select, sync::mpsc, time::interval};
use tokio::{select, sync::mpsc};
use windmill_common::METRICS_ENABLED;
use crate::db::DB;
@@ -78,8 +79,7 @@ impl WebhookShared {
.timeout(Duration::from_secs(5))
.build()
.unwrap();
let cache = retainer::Cache::new();
let mut cache_purge_interval = interval(Duration::from_secs(30));
let cache = Cache::new(100);
loop {
select! {
@@ -87,7 +87,7 @@ impl WebhookShared {
_ = shutdown_rx.recv() => break,
r = rx.recv() => match r {
Some(WebhookPayload::WorkspaceEvent(workspace_id, message)) => {
let url_guard = match cache.get(&workspace_id).await {
let webhook_opt = match cache.get(&workspace_id) {
Some(guard) => {
guard
},
@@ -104,16 +104,14 @@ impl WebhookShared {
tracing::error!("Webhook Message to send - but cannot get workspace settings! Workspace: {workspace_id}");
continue;
};
cache.insert(workspace_id.clone(), webook_opt, Duration::from_secs(30)).await;
cache.get(&workspace_id).await.unwrap()
cache.insert(workspace_id, webook_opt.clone());
webook_opt
}
};
let webook_opt = url_guard.value();
if let Some(url) = webook_opt {
if let Some(url) = webhook_opt {
let timer = if *METRICS_ENABLED { Some(WEBHOOK_REQUEST_COUNT.start_timer()) } else { None };
let _ = client.post(url).json(&message).send().await;
timer.map(|x| x.stop_and_record());
drop(url_guard);
}
},
Some(WebhookPayload::InstanceEvent(event)) => {
@@ -125,10 +123,6 @@ impl WebhookShared {
},
None => break,
},
_ = futures::future::poll_fn(|cx| cache_purge_interval.poll_tick(cx)) => {
tracing::trace!("Purging Webhook Cache");
cache.purge(10, 0.50).await;
},
}
}
});