Skip to content

Commit 1585e88

Browse files
committed
backend: re-work job table usages after v2
1 parent 279cefd commit 1585e88

10 files changed

+387
-310
lines changed

backend/.sqlx/query-111ee00fa6661fd4d3bb1d2e567fdaa1cbd3fe93b590b97c549ff2ad0016da1a.json

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/.sqlx/query-3af91bb37638473d3d97a3a6f7fc6c6927ac0a6f6c26f11db69fbc4aa839cf64.json

Lines changed: 91 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/.sqlx/query-4a4971ab285cc5ca0dc4026d75a31981cb91ccabdaa786ebadb6d80e8a8b38db.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/.sqlx/query-ebd8349ebda8ecb57e15257233a7ac50acac152fc0a5315e90fce6d0abeac652.json

Lines changed: 67 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/windmill-api/src/jobs.rs

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
use axum::body::Body;
1010
use axum::http::HeaderValue;
11-
use futures::TryFutureExt;
1211
use itertools::Itertools;
1312
use quick_cache::sync::Cache;
1413
use serde_json::value::RawValue;
@@ -792,38 +791,25 @@ impl<'a> GetQuery<'a> {
792791
async fn resolve_raw_values<T>(
793792
&self,
794793
db: &DB,
795-
id: Uuid,
796794
kind: JobKind,
797-
hash: Option<ScriptHash>,
795+
runnable_id: Option<i64>,
798796
job: &mut JobExtended<T>,
799797
) {
800-
let (raw_code, raw_lock, raw_flow) = (
801-
job.raw_code.take(),
802-
job.raw_lock.take(),
803-
job.raw_flow.take(),
804-
);
805-
if self.with_flow {
806-
// Try to fetch the flow from the cache, fallback to the preview flow.
807-
// NOTE: This could check for the job kinds instead of the `or_else` but it's not
808-
// necessary as `fetch_flow` return early if the job kind is not a preview one.
809-
cache::job::fetch_flow(db, kind, hash)
810-
.or_else(|_| cache::job::fetch_preview_flow(db, &id, raw_flow))
798+
job.raw_flow = match job.raw_flow.take() {
799+
_ if !self.with_flow => None,
800+
flow => cache::job::fetch_flow(db, kind, runnable_id, flow)
811801
.await
812802
.ok()
813-
.inspect(|data| job.raw_flow = Some(sqlx::types::Json(data.raw_flow.clone())));
814-
}
815-
if self.with_code {
816-
// Try to fetch the code from the cache, fallback to the preview code.
817-
// NOTE: This could check for the job kinds instead of the `or_else` but it's not
818-
// necessary as `fetch_script` return early if the job kind is not a preview one.
819-
cache::job::fetch_script(db, kind, hash)
820-
.or_else(|_| cache::job::fetch_preview_script(db, &id, raw_lock, raw_code))
803+
.map(|data| sqlx::types::Json(data.raw_flow.clone())),
804+
};
805+
(job.raw_code, job.raw_lock) = match (job.raw_code.take(), job.raw_lock.take()) {
806+
_ if !self.with_code => (None, None),
807+
(code, lock) => cache::job::fetch_script(db, kind, runnable_id, code, lock)
821808
.await
822809
.ok()
823-
.inspect(|data| {
824-
(job.raw_lock, job.raw_code) = (data.lock.clone(), Some(data.code.clone()))
825-
});
826-
}
810+
.map(|data| (Some(data.code.clone()), data.lock.clone()))
811+
.unwrap_or_default(),
812+
};
827813
}
828814

829815
async fn fetch_queued(
@@ -846,7 +832,7 @@ impl<'a> GetQuery<'a> {
846832

847833
self.check_auth(job.as_ref().map(|job| job.created_by.as_str()))?;
848834
if let Some(job) = job.as_mut() {
849-
self.resolve_raw_values(db, job.id, job.job_kind, job.script_hash, job)
835+
self.resolve_raw_values(db, job.job_kind, job.script_hash.map(|x| x.0), job)
850836
.await;
851837
}
852838
if self.with_flow {
@@ -878,7 +864,7 @@ impl<'a> GetQuery<'a> {
878864

879865
self.check_auth(cjob.as_ref().map(|job| job.created_by.as_str()))?;
880866
if let Some(job) = cjob.as_mut() {
881-
self.resolve_raw_values(db, job.id, job.job_kind, job.script_hash, job)
867+
self.resolve_raw_values(db, job.job_kind, job.script_hash.map(|x| x.0), job)
882868
.await;
883869
}
884870
if self.with_flow {

backend/windmill-api/src/slack_approvals.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use windmill_common::{
2222
cache,
2323
error::{self, Error},
2424
jobs::JobKind,
25-
scripts::ScriptHash,
2625
variables::{build_crypt, decrypt_value_with_mc},
2726
};
2827

@@ -978,7 +977,7 @@ async fn get_modal_blocks(
978977
let (job_kind, script_hash, raw_flow, parent_job_id, created_at, created_by, script_path, args) = sqlx::query!(
979978
"SELECT
980979
v2_queue.job_kind AS \"job_kind!: JobKind\",
981-
v2_queue.script_hash AS \"script_hash: ScriptHash\",
980+
v2_queue.script_hash,
982981
v2_queue.raw_flow AS \"raw_flow: sqlx::types::Json<Box<RawValue>>\",
983982
v2_completed_job.parent_job AS \"parent_job: Uuid\",
984983
v2_completed_job.created_at AS \"created_at!: chrono::NaiveDateTime\",
@@ -998,17 +997,11 @@ async fn get_modal_blocks(
998997
.ok_or_else(|| error::Error::BadRequest("This workflow is no longer running and has either already timed out or been cancelled or completed.".to_string()))
999998
.map(|r| (r.job_kind, r.script_hash, r.raw_flow, r.parent_job, r.created_at, r.created_by, r.script_path, r.args))?;
1000999

1001-
let flow_data = match cache::job::fetch_flow(&db, job_kind, script_hash).await {
1000+
let flow_data = match cache::job::fetch_flow(&db, job_kind, script_hash, raw_flow).await {
10021001
Ok(data) => data,
1003-
Err(_) => {
1004-
if let Some(parent_job_id) = parent_job_id.as_ref() {
1005-
cache::job::fetch_preview_flow(&db, parent_job_id, raw_flow).await?
1006-
} else {
1007-
return Err(error::Error::BadRequest(
1008-
"This workflow is no longer running and has either already timed out or been cancelled or completed.".to_string(),
1009-
));
1010-
}
1011-
}
1002+
Err(_) => return Err(error::Error::BadRequest(
1003+
"This workflow is no longer running and has either already timed out or been cancelled or completed.".to_string(),
1004+
))
10121005
};
10131006

10141007
let flow_value = &flow_data.flow;

0 commit comments

Comments
 (0)