Skip to content

Commit

Permalink
feat: validate worker upon job update
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Mar 11, 2024
1 parent 82a45b4 commit cc95c89
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions server/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
models::{Job, NewWorker, Pipeline, Worker},
DbPool, ARGS,
};
use anyhow::anyhow;
use anyhow::Context;
use axum::{
extract::{Json, State},
Expand Down Expand Up @@ -196,6 +197,15 @@ pub async fn worker_job_update(
.find(payload.job_id)
.first::<Job>(&mut conn)?;

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>(&mut conn)?;

if job.status != "assigned" || job.assigned_worker_id != Some(worker.id) {
return Err(anyhow!("Worker not assigned to the job").into());
}

let pipeline = crate::schema::pipelines::dsl::pipelines
.find(job.pipeline_id)
.first::<Pipeline>(&mut conn)?;
Expand Down

0 comments on commit cc95c89

Please sign in to comment.