diff --git a/backend/sqlx-data.json b/backend/sqlx-data.json index bdfdb99c32..2e0cb5d350 100644 --- a/backend/sqlx-data.json +++ b/backend/sqlx-data.json @@ -5308,6 +5308,33 @@ }, "query": "INSERT INTO group_\n VALUES ($1, 'all', 'The group that always contains all users of this workspace')" }, + "cd9c254f43fa689245a7e42fe9127d4a53e12fa85e14ae4ab9c1b23691cfdcae": { + "describe": { + "columns": [ + { + "name": "hash", + "ordinal": 0, + "type_info": "Int8" + }, + { + "name": "tag", + "ordinal": 1, + "type_info": "Varchar" + } + ], + "nullable": [ + false, + true + ], + "parameters": { + "Left": [ + "Text", + "Text" + ] + } + }, + "query": "select hash, tag from script where path = $1 AND workspace_id = $2 AND\n created_at = (SELECT max(created_at) FROM script WHERE path = $1 AND workspace_id = $2 AND\n deleted = false AND archived = false)" + }, "d0308abac80575038203b60bb66d3b39b586939da0421a595e47c7a759616431": { "describe": { "columns": [], diff --git a/backend/windmill-common/src/lib.rs b/backend/windmill-common/src/lib.rs index 29f13fa0d9..7c670a4322 100644 --- a/backend/windmill-common/src/lib.rs +++ b/backend/windmill-common/src/lib.rs @@ -168,3 +168,24 @@ pub async fn get_latest_deployed_hash_for_path<'c>( Ok((scripts::ScriptHash(script.hash), script.tag)) } + + +pub async fn get_latest_hash_for_path<'c>( + db: &mut sqlx::Transaction<'c, sqlx::Postgres>, + w_id: &str, + script_path: &str, +) -> error::Result<(scripts::ScriptHash, Option)> { + let r_o = sqlx::query!( + "select hash, tag from script where path = $1 AND workspace_id = $2 AND + created_at = (SELECT max(created_at) FROM script WHERE path = $1 AND workspace_id = $2 AND + deleted = false AND archived = false)", + script_path, + w_id + ) + .fetch_optional(db) + .await?; + + let script = utils::not_found_if_none(r_o, "script", script_path)?; + + Ok((scripts::ScriptHash(script.hash), script.tag)) +} diff --git a/backend/windmill-queue/src/schedule.rs b/backend/windmill-queue/src/schedule.rs index ee068920b6..9c12b4d4ff 100644 --- a/backend/windmill-queue/src/schedule.rs +++ b/backend/windmill-queue/src/schedule.rs @@ -70,7 +70,7 @@ pub async fn push_scheduled_job<'c, R: rsmq_async::RsmqConnection + Send + 'c>( let (payload, tag) = if schedule.is_flow { (JobPayload::Flow(schedule.script_path), None) } else { - let (hash, tag) = windmill_common::get_latest_deployed_hash_for_path( + let (hash, tag) = windmill_common::get_latest_hash_for_path( tx.transaction_mut(), &schedule.workspace_id, &schedule.script_path,