Skip to content

Commit

Permalink
feat: un-assign job even if no new job is assigned
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Mar 22, 2024
1 parent cf91ae2 commit a0c74a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions server/src/routes/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@ pub async fn worker_poll(
match conn.transaction::<Option<(Pipeline, Job)>, 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::<Worker>(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::<i32>)))
.execute(conn)?;

let mut sql = jobs.filter(status.eq("created")).into_boxed();
if payload.arch == "amd64" {
// route noarch to amd64
Expand Down Expand Up @@ -206,17 +217,6 @@ pub async fn worker_poll(
let res = sql.first::<Job>(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::<Worker>(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::<i32>)))
.execute(conn)?;

// allocate to the worker
diesel::update(&job)
.set((status.eq("running"), assigned_worker_id.eq(worker.id)))
Expand Down

0 comments on commit a0c74a5

Please sign in to comment.