Skip to content

Commit 803689c

Browse files
committed
refactor(server): read a job's published snapshot through the stored job record
1 parent f9108d1 commit 803689c

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

‎crates/sqlbuild-orchestration/src/declarations/main/read_person_job.rs‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use crate::declarations::_helpers::job_detail::{
88
critical_nodes, groups_running, members_in_order, shown_settings,
99
};
1010
use crate::declarations::main::frozen_definitions::frozen_definitions;
11-
use crate::declarations::models::JobDetailRecord;
11+
use crate::declarations::models::{JobDetailRecord, StoredJob};
1212
use crate::runs::models::RunKind;
1313
use crate::snapshots::main::read_snapshot_nodes::read_snapshot_nodes;
1414
use crate::store::errors::ControlError;
15-
use crate::store::main::{begin::begin, commit::commit, query::query};
15+
use crate::store::main::{begin::begin, commit::commit, query_records::query_records};
1616
use crate::store::models::{ControlStore, ControlTransaction, Parameter, TransactionMode};
1717

1818
/// `None` when the target publishes no job by that name; refusal comes first either way.
@@ -70,20 +70,16 @@ async fn published_snapshot(
7070
transaction: ControlTransaction,
7171
(location_id, target, job_key): (Uuid, &str, &str),
7272
) -> Result<(ControlTransaction, Option<Uuid>), ControlError> {
73-
let (transaction, rows) = query(
73+
let (transaction, stored): (_, Vec<StoredJob>) = query_records(
7474
transaction,
75-
"SELECT snapshot_id FROM sqb_jobs WHERE location_id=$1 AND target=$2 AND job_key=$3",
75+
"SELECT job_key, kind, snapshot_id, definition_json FROM sqb_jobs \
76+
WHERE location_id=$1 AND target=$2 AND job_key=$3",
7677
vec![
7778
Parameter::Id(location_id),
7879
Parameter::Text(target.into()),
7980
Parameter::Text(job_key.into()),
8081
],
8182
)
8283
.await?;
83-
let snapshot_id = rows
84-
.first()
85-
.map(|row| serde_json::from_value(row["snapshot_id"].clone()))
86-
.transpose()
87-
.map_err(|error| ControlError::Invalid(error.to_string()))?;
88-
Ok((transaction, snapshot_id))
84+
Ok((transaction, stored.first().map(|job| job.snapshot_id)))
8985
}

0 commit comments

Comments
 (0)