From c0607d0948d2c315da892d3dc5385512afcb4291 Mon Sep 17 00:00:00 2001 From: Ynah537 Date: Tue, 26 May 2026 10:57:40 +0800 Subject: [PATCH] fix: prioritize run_id when provided --- main.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index 78bd310..44e6708 100644 --- a/main.go +++ b/main.go @@ -429,15 +429,21 @@ func (a *appctx) isRunCancelled(runID string, commitSha string) bool { ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) defer cancel() - stmt := spanner.Statement{ - SQL: fmt.Sprintf(`SELECT run_id FROM %s - WHERE (run_id = @run_id OR commit_sha = @commit_sha) - AND status = 'closed' - LIMIT 1`, spannercanceltable), - Params: map[string]interface{}{ - "run_id": runID, - "commit_sha": commitSha, - }, + var stmt spanner.Statement + if runID != "" { + stmt = spanner.Statement{ + SQL: fmt.Sprintf(`SELECT run_id FROM %s WHERE run_id = @run_id AND status = 'closed' LIMIT 1`, spannercanceltable), + Params: map[string]interface{}{ + "run_id": runID, + }, + } + } else { + stmt = spanner.Statement{ + SQL: fmt.Sprintf(`SELECT run_id FROM %s WHERE commit_sha = @commit_sha AND status = 'closed' LIMIT 1`, spannercanceltable), + Params: map[string]interface{}{ + "commit_sha": commitSha, + }, + } } found := false @@ -445,10 +451,6 @@ func (a *appctx) isRunCancelled(runID string, commitSha string) bool { found = true return nil }) - if found { - return true - } - return found }