From bb5ce15e13318b4cf15aa018a63caa7006f3c15e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=B6hmwalder?= Date: Thu, 4 Jan 2024 19:14:15 +0100 Subject: [PATCH] add UniqueSkippedAsDuplicate field to JobRow When inserting a job, the insert may be rejected because the configured uniqueness constraints for the job are not met. With the current API, this happens silently and without a way for the caller to check for this condition. Since we already record the UniqueSkippedAsDuplicate in the internal dbadapter.JobInsertResult, we just have to propagate this value to the external client API. Callers can now check the UniqueSkippedAsDuplicate field of JobRow to check for the condition described above. --- client.go | 4 +++- rivertype/job_row.go | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 919014fe..5529061a 100644 --- a/client.go +++ b/client.go @@ -1066,7 +1066,9 @@ func (c *Client[TTx]) InsertTx(ctx context.Context, tx TTx, args JobArgs, opts * return nil, err } - return dbsqlc.JobRowFromInternal(res.Job), nil + jobRow := dbsqlc.JobRowFromInternal(res.Job) + jobRow.UniqueSkippedAsDuplicate = res.UniqueSkippedAsDuplicate + return jobRow, nil } // InsertManyParams encapsulates a single job combined with insert options for diff --git a/rivertype/job_row.go b/rivertype/job_row.go index f3aac8b0..562a63d0 100644 --- a/rivertype/job_row.go +++ b/rivertype/job_row.go @@ -94,6 +94,11 @@ type JobRow struct { // functional behavior and are meant entirely as a user-specified construct // to help group and categorize jobs. Tags []string + + // UniqueSkippedAsDuplicate indicates that the insert didn't occur because + // it was a unique job, and another unique job within the unique parameters + // was already in the database. + UniqueSkippedAsDuplicate bool } // JobState is the state of a job. Jobs start as `available` or `scheduled`, and