feat(backend): add JOB_RETENTION_SECS to delete completed jobs completed after expiration period

This commit is contained in:
Ruben Fiszel
2023-04-26 19:34:54 +02:00
parent 6edc7d9978
commit 1d1c812e36
4 changed files with 32 additions and 7 deletions
+1
View File
@@ -338,6 +338,7 @@ it being synced automatically everyday.
| GLOBAL_CACHE_INTERVAL | 10\*60 | (Enterprise Edition only) Interval in seconds in between bucket sync of the cache. This interval \* 2 is the time at which you're guaranteed all the worker's caches are synced together. | Worker |
| WORKER_TAGS | 'deno,go,python3,bash,flow,hub,dependency' | The worker groups assigned to that workers | Worker |
| CUSTOM_TAGS | None | The custom tags assignable to scripts. | Server |
| JOB_RETENTION_SECS | 60*60*24\*60 //60 days | The time in seconds after which jobs get deleted. Set to 0 or -1 to never delete | Server |
## Run a local dev setup
+20
View File
@@ -1945,6 +1945,26 @@
},
"query": "INSERT INTO pip_resolution_cache (hash, lockfile, expiration) VALUES ($1, $2, now() + ('3 days')::interval) ON CONFLICT (hash) DO UPDATE SET lockfile = $2"
},
"502781c4e2fc692db7a66b850450a1934b2403a5cff0421fe9609f9b99d8ee95": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Uuid"
}
],
"nullable": [
false
],
"parameters": {
"Left": [
"Int4"
]
}
},
"query": "DELETE FROM completed_job WHERE started_at + ((duration_ms/1000 + $1) || ' s')::interval <= now() RETURNING id"
},
"5061c0d054bf4f028e7fe51a8f9389024c6ae4492755cadac0f7167e5300bda0": {
"describe": {
"columns": [],
+6 -2
View File
@@ -16,6 +16,7 @@ use monitor::handle_zombie_jobs_periodically;
use sqlx::{Pool, Postgres};
use tokio::{
fs::{metadata, DirBuilder},
join,
sync::RwLock,
};
use windmill_common::{utils::rd_string, METRICS_ADDR};
@@ -164,6 +165,7 @@ Windmill Community Edition {GIT_VERSION}
"GLOBAL_CACHE_INTERVAL",
"WORKER_TAGS",
"CUSTOM_TAGS",
"JOB_RETENTION_SECS",
]);
if server_mode || num_workers > 0 {
@@ -246,9 +248,11 @@ pub fn monitor_db<R: rsmq_async::RsmqConnection + Send + Sync + Clone + 'static>
let rx2 = rx.resubscribe();
let base_internal_url = base_internal_url.to_string();
tokio::spawn(async move {
handle_zombie_jobs_periodically(&db1, rx, &base_internal_url, rsmq).await
join!(
handle_zombie_jobs_periodically(&db1, rx, &base_internal_url, rsmq),
windmill_api::delete_expired_items_perdiodically(&db2, rx2)
);
});
tokio::spawn(async move { windmill_api::delete_expired_items_perdiodically(&db2, rx2).await });
}
pub async fn run_workers<R: rsmq_async::RsmqConnection + Send + Sync + Clone + 'static>(
+5 -5
View File
@@ -144,7 +144,7 @@ pub struct Metrics {
}
pub const DEFAULT_TIMEOUT: u16 = 300;
pub const DEFAULT_TIMEOUT: u64 = 300;
pub const DEFAULT_SLEEP_QUEUE: u64 = 50;
lazy_static::lazy_static! {
@@ -213,12 +213,12 @@ lazy_static::lazy_static! {
"Total number of seconds since the worker has started"
);
static ref TIMEOUT: u16 = std::env::var("TIMEOUT")
static ref TIMEOUT: u64 = std::env::var("TIMEOUT")
.ok()
.and_then(|x| x.parse::<u16>().ok())
.unwrap_or(DEFAULT_TIMEOUT as u16);
.and_then(|x| x.parse::<u64>().ok())
.unwrap_or(DEFAULT_TIMEOUT);
static ref TIMEOUT_DURATION: Duration = Duration::from_secs(*TIMEOUT as u64);
static ref TIMEOUT_DURATION: Duration = Duration::from_secs(*TIMEOUT);
pub static ref SESSION_TOKEN_EXPIRY: i32 = (*TIMEOUT as i32) * 2;