From a0c74a568c314e1f57b153f3dd70fba51fe326b7 Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Fri, 22 Mar 2024 15:46:53 +0800 Subject: [PATCH] feat: un-assign job even if no new job is assigned --- README.md | 2 +- server/src/routes/worker.rs | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f56b349..58a335d 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Steps (as root): 3. `cd /buildroots/buildit && ciel new`, making sure to create an instance named "main" when asked 4. `cp /buildroots/buildit/buildit/systemd/buildit-worker.service /etc/systemd/system` 5. `$EDITOR /etc/systemd/system/buildit-worker.service`:update ARCH -6. `$EDITOR /buildroots/buildit/buildit/.env`: set BUILDIT_SERVER, BUILDIT_WORKER_SECRET and BUILDIT_SSH_KEY; for workers in China, optionally update BUILDIT_RSYNC_HOST to repo-cn.aosc.io +6. `$EDITOR /buildroots/buildit/buildit/.env`: set BUILDIT_SERVER, BUILDIT_WORKER_SECRET BUILDIT_SSH_KEY and BUILDIT_WORKER_PERFORMANCE; for workers in China, optionally update BUILDIT_RSYNC_HOST to repo-cn.aosc.io 7. `systemctl enable --now buildit-worker` 8. `chmod 600 /buildroots/buildit/buildit/.env` 9. Setup SSH key of AOSC Maintainers at the location of BUILDIT_SSH_KEY diff --git a/server/src/routes/worker.rs b/server/src/routes/worker.rs index c5ff2f1..10c18a9 100644 --- a/server/src/routes/worker.rs +++ b/server/src/routes/worker.rs @@ -171,6 +171,17 @@ pub async fn worker_poll( match conn.transaction::, diesel::result::Error, _>(|conn| { use crate::schema::jobs::dsl::*; + // find worker id + let worker = crate::schema::workers::dsl::workers + .filter(crate::schema::workers::dsl::hostname.eq(&payload.hostname)) + .filter(crate::schema::workers::dsl::arch.eq(&payload.arch)) + .first::(conn)?; + + // remove if any job is already allocated to the worker + diesel::update(jobs.filter(assigned_worker_id.eq(worker.id))) + .set((status.eq("created"), assigned_worker_id.eq(None::))) + .execute(conn)?; + let mut sql = jobs.filter(status.eq("created")).into_boxed(); if payload.arch == "amd64" { // route noarch to amd64 @@ -206,17 +217,6 @@ pub async fn worker_poll( let res = sql.first::(conn).optional()?; match res { Some(job) => { - // find worker id - let worker = crate::schema::workers::dsl::workers - .filter(crate::schema::workers::dsl::hostname.eq(&payload.hostname)) - .filter(crate::schema::workers::dsl::arch.eq(&payload.arch)) - .first::(conn)?; - - // remove if already allocated to the worker - diesel::update(jobs.filter(assigned_worker_id.eq(worker.id))) - .set((status.eq("created"), assigned_worker_id.eq(None::))) - .execute(conn)?; - // allocate to the worker diesel::update(&job) .set((status.eq("running"), assigned_worker_id.eq(worker.id)))