Skip to content

Commit eec5b64

Browse files
authored
backend: use the same Tx when puhsing a flow (#4952)
1 parent 3339e69 commit eec5b64

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

backend/.sqlx/query-97048ce0bcabb9baecb80cde5ab3c989e1575fbd20ef22766d2887a86dce15e1.json

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

backend/windmill-queue/src/jobs.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,35 +3190,34 @@ pub async fn push<'c, 'd>(
31903190
)
31913191
}
31923192
JobPayload::Flow { path, dedicated_worker, apply_preprocessor } => {
3193+
let mut ntx = tx.into_tx().await?;
31933194
// Fetch the latest version of the flow.
3194-
// Note that this query is performed within an isolated transaction to secure the
3195-
// API surface.
3196-
let version = fetch_scalar_isolated!(
3197-
sqlx::query_scalar!(
3198-
"SELECT flow.versions[array_upper(flow.versions, 1)] AS \"version!: i64\"
3199-
FROM flow WHERE path = $1 AND workspace_id = $2",
3200-
&path,
3201-
&workspace_id
3202-
),
3203-
tx
3204-
)?
3195+
let version = sqlx::query_scalar!(
3196+
"SELECT flow.versions[array_upper(flow.versions, 1)] AS \"version!: i64\"
3197+
FROM flow WHERE path = $1 AND workspace_id = $2",
3198+
&path,
3199+
&workspace_id
3200+
)
3201+
.fetch_optional(&mut *ntx)
3202+
.await?
32053203
.ok_or_else(|| Error::InternalErr(format!("not found flow at path {:?}", path)))?;
32063204

32073205
// Do not use the lite version unless all workers are updated.
3208-
// This does not need to be performed within the isolated Tx as checks had been
3209-
// performed before when the version was fetched.
32103206
let data = if *DISABLE_FLOW_SCRIPT
32113207
|| (!*MIN_VERSION_IS_AT_LEAST_1_432.read().await && !*CLOUD_HOSTED)
32123208
{
3213-
cache::flow::fetch_version(_db, version).await
3209+
cache::flow::fetch_version(&mut *ntx, version).await
32143210
} else {
32153211
// Fallback to the original version if the lite version is not found.
32163212
// This also prevent a race condition where the flow is run just after deploy and
32173213
// the lite version is still being created.
3218-
cache::flow::fetch_version_lite(_db, version)
3219-
.or_else(|_| cache::flow::fetch_version(_db, version))
3220-
.await
3214+
match cache::flow::fetch_version_lite(&mut *ntx, version).await {
3215+
Ok(data) => Ok(data),
3216+
Err(_) => cache::flow::fetch_version(&mut *ntx, version).await,
3217+
}
32213218
}?;
3219+
tx = PushIsolationLevel::Transaction(ntx);
3220+
32223221
let value = data.value()?.clone();
32233222
let priority = value.priority;
32243223
let cache_ttl = value.cache_ttl.map(|x| x as i32);

0 commit comments

Comments
 (0)