Correct Way to Enforce Uniqueness on Insertion By Kind and Default States #704
-
I think I might be missing something with regard to the best way to specify uniqueness by kind and the default list of states. The default value for {
ExcludeKind: false
} This seems redundant, as this is already the default value. However, if I just provide an empty struct uniqueness won't be enforced at all. Is this the intended behavior? It would seem to be that |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Yes, it's intended behavior — checking a struct is zero valued versus not is generally a bit more conventional in Go compared to check a pointer.
Honestly, we've never gotten this request before. Usually when you're checking for uniqueness you're trying to do it on some other dimension beyond just the job's kind like period. As things stand, you might have to use something like ByState: []rivertype.JobState{rivertype.JobStateAvailable, rivertype.JobStateCompleted, rivertype.JobStatePending, rivertype.JobStateRunning, rivertype.JobStateRetryable, rivertype.JobStateScheduled} I suppose one could argue that unique opts should have been made a pointer originally for this case, but at this point, that API isn't going to be changing, so another route will need to be found. |
Beta Was this translation helpful? Give feedback.
Yes, it's intended behavior — checking a struct is zero valued versus not is generally a bit more conventional in Go compared to check a pointer.
ExcludeKind: false
won't work becausefalse
is the zero value for a boolean so there's no way in Go to check whether you set afalse
value explicitly versus got a default zero value.Honestly, we've never gotten this request before. Usually when you're checking for uniqueness you're trying to do it on some other dimension beyond just the job's kind like period. As things stand, you might have to use something like
ByArgs: true
(if your args are stable), or set the list of default unique states: