fix: handle more gracefully worker without tags

This commit is contained in:
Ruben Fiszel
2024-08-20 16:27:01 +02:00
parent f237d12330
commit 7e1f28071a
2 changed files with 18 additions and 0 deletions
+8
View File
@@ -86,6 +86,10 @@ lazy_static::lazy_static! {
}
pub async fn make_suspended_pull_query(wc: &WorkerConfig) {
if wc.worker_tags.len() == 0 {
tracing::error!("Empty tags in worker tags, skipping");
return;
}
let query = format!(
"UPDATE queue
SET running = true
@@ -114,6 +118,10 @@ pub async fn make_suspended_pull_query(wc: &WorkerConfig) {
pub async fn make_pull_query(wc: &WorkerConfig) {
let mut queries = vec![];
for tags in wc.priority_tags_sorted.iter() {
if tags.tags.len() == 0 {
tracing::error!("Empty tags in priority tags, skipping");
continue;
}
let query = format!("UPDATE queue
SET running = true
, started_at = coalesce(started_at, now())
+10
View File
@@ -1967,6 +1967,11 @@ async fn pull_single_job_and_mark_as_running_no_concurrency_limit<
* or suspend_until <= now() if it has timed out */
let query = WORKER_SUSPENDED_PULL_QUERY.read().await;
if query.is_empty() {
tracing::warn!("No suspended pull queries available");
return Ok(None);
}
let r = if suspend_first {
// tracing::info!("Pulling job with query: {}", query);
sqlx::query_as::<_, QueuedJob>(&query)
@@ -1982,6 +1987,11 @@ async fn pull_single_job_and_mark_as_running_no_concurrency_limit<
let queries = WORKER_PULL_QUERIES.read().await;
if queries.is_empty() {
tracing::warn!("No pull queries available");
return Ok(None);
}
for query in queries.iter() {
// tracing::info!("Pulling job with query: {}", query);
let r = sqlx::query_as::<_, QueuedJob>(query)