MCPcopy Index your code
hub / github.com/riverqueue/river / validate

Method validate

insert_opts.go:251–287  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

249}
250
251func (o *UniqueOpts) validate() error {
252 if o.isEmpty() {
253 return nil
254 }
255
256 if o.ByPeriod != time.Duration(0) && o.ByPeriod < 1*time.Second {
257 return errors.New("UniqueOpts.ByPeriod should not be less than 1 second")
258 }
259
260 // Job states are typed, but since the underlying type is a string, users
261 // can put anything they want in there.
262 for _, state := range o.ByState {
263 // This could be turned to a map lookup, but last I checked the speed
264 // difference for tiny slice sizes is negligible, and map lookup might
265 // even be slower.
266 if !slices.Contains(jobStateAll, state) {
267 return fmt.Errorf("UniqueOpts.ByState contains invalid state %q", state)
268 }
269 }
270
271 // Skip required states validation if no custom states were provided.
272 if len(o.ByState) == 0 {
273 return nil
274 }
275
276 var missingStates []string
277 for _, state := range requiredV3states {
278 if !slices.Contains(o.ByState, state) {
279 missingStates = append(missingStates, string(state))
280 }
281 }
282 if len(missingStates) > 0 {
283 return fmt.Errorf("UniqueOpts.ByState must contain all required states, missing: %s", strings.Join(missingStates, ", "))
284 }
285
286 return nil
287}

Callers 1

Calls 2

isEmptyMethod · 0.95
ErrorfMethod · 0.65

Tested by

no test coverage detected