fix: restart zombie jobs was restarting all jobs

This commit is contained in:
Ruben Fiszel
2022-08-21 12:17:32 +02:00
parent 59140a570c
commit e18f814d77
2 changed files with 39 additions and 28 deletions
+32 -26
View File
@@ -922,32 +922,6 @@
]
}
},
"4b11072143dc520fe59eb4100982a1cf1a529c79083bdd57ec84ed30b699d426": {
"query": "UPDATE queue SET running = false WHERE last_ping < now() + ($1 || ' seconds')::interval and running = true RETURNING id, workspace_id",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Uuid"
},
{
"ordinal": 1,
"name": "workspace_id",
"type_info": "Varchar"
}
],
"parameters": {
"Left": [
"Text"
]
},
"nullable": [
false,
false
]
}
},
"4e8ff055a80cc2e6b7fd6653c0c8e9a0e4b223a4bdeab0cf43dc79ce10f635b9": {
"query": "INSERT INTO workspace\n (id, name, owner, domain)\n VALUES ($1, $2, $3, $4)",
"describe": {
@@ -2708,6 +2682,38 @@
]
}
},
"c78b52b350193135d2b9fcf04d3113f7504cc61f6414f809d8a9c51a16f20d35": {
"query": "UPDATE queue SET running = false WHERE last_ping < now() - ($1 || ' seconds')::interval and running = true RETURNING id, workspace_id, last_ping",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Uuid"
},
{
"ordinal": 1,
"name": "workspace_id",
"type_info": "Varchar"
},
{
"ordinal": 2,
"name": "last_ping",
"type_info": "Timestamptz"
}
],
"parameters": {
"Left": [
"Text"
]
},
"nullable": [
false,
false,
false
]
}
},
"cac594031a21b4806de9c4616317d3541522ef9712a83ecff7bd8b5f6e870748": {
"query": "UPDATE account SET refresh_token = $1, expires_at = $2 WHERE workspace_id = $3 AND id = $4",
"describe": {
+7 -2
View File
@@ -1190,7 +1190,7 @@ pub async fn restart_zombie_jobs_periodically(
) {
loop {
let restarted = sqlx::query!(
"UPDATE queue SET running = false WHERE last_ping < now() + ($1 || ' seconds')::interval and running = true RETURNING id, workspace_id",
"UPDATE queue SET running = false WHERE last_ping < now() - ($1 || ' seconds')::interval and running = true RETURNING id, workspace_id, last_ping",
(timeout * 5).to_string(),
)
.fetch_all(db)
@@ -1199,7 +1199,12 @@ pub async fn restart_zombie_jobs_periodically(
.unwrap_or_else(|| vec![]);
for r in restarted {
tracing::info!("restarted zombie job {} {}", r.id, r.workspace_id);
tracing::info!(
"restarted zombie job {} {} {}",
r.id,
r.workspace_id,
r.last_ping
);
}
tokio::select! {