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

Function insertParamsFromConfigArgsAndOptions

client.go:1705–1809  ·  view source on GitHub ↗
(archetype *baseservice.Archetype, config *Config, args JobArgs, insertOpts *InsertOpts)

Source from the content-addressed store, hash-verified

1703}
1704
1705func insertParamsFromConfigArgsAndOptions(archetype *baseservice.Archetype, config *Config, args JobArgs, insertOpts *InsertOpts) (*rivertype.JobInsertParams, error) {
1706 encodedArgs, err := json.Marshal(args)
1707 if err != nil {
1708 return nil, fmt.Errorf("error marshaling args to JSON: %w", err)
1709 }
1710
1711 if insertOpts == nil {
1712 insertOpts = &InsertOpts{}
1713 }
1714
1715 var jobInsertOpts InsertOpts
1716 if argsWithOpts, ok := args.(JobArgsWithInsertOpts); ok {
1717 jobInsertOpts = argsWithOpts.InsertOpts()
1718 }
1719
1720 // If the time is stubbed (in a test), use that for `created_at`. Otherwise,
1721 // leave an empty value which will either use the database's `now()` or be defaulted
1722 // by drivers as necessary.
1723 createdAt := archetype.Time.NowOrNil()
1724
1725 maxAttempts := cmp.Or(insertOpts.MaxAttempts, jobInsertOpts.MaxAttempts, config.MaxAttempts)
1726 priority := cmp.Or(insertOpts.Priority, jobInsertOpts.Priority, rivercommon.PriorityDefault)
1727 queue := cmp.Or(insertOpts.Queue, jobInsertOpts.Queue, rivercommon.QueueDefault)
1728
1729 if err := validateQueueName(queue); err != nil {
1730 return nil, err
1731 }
1732
1733 tags := insertOpts.Tags
1734 if insertOpts.Tags == nil {
1735 tags = jobInsertOpts.Tags
1736 }
1737 if tags == nil {
1738 tags = []string{}
1739 } else {
1740 for _, tag := range tags {
1741 if len(tag) > 255 {
1742 return nil, errors.New("tags should be a maximum of 255 characters long")
1743 }
1744 if !tagRE.MatchString(tag) {
1745 return nil, errors.New("tags should match regex " + tagRE.String())
1746 }
1747 }
1748 }
1749
1750 if priority < 1 || priority > 4 {
1751 return nil, errors.New("priority must be between 1 and 4")
1752 }
1753
1754 var uniqueOpts UniqueOpts
1755 if !config.Test.DisableUniqueEnforcement {
1756 uniqueOpts = insertOpts.UniqueOpts
1757 if uniqueOpts.isEmpty() {
1758 uniqueOpts = jobInsertOpts.UniqueOpts
1759 }
1760 }
1761 if err := uniqueOpts.validate(); err != nil {
1762 return nil, err

Calls 9

isEmptyMethod · 0.95
validateMethod · 0.95
UniqueKeyFunction · 0.92
validateQueueNameFunction · 0.85
StateBitmaskMethod · 0.80
ErrorfMethod · 0.65
InsertOptsMethod · 0.65
NowOrNilMethod · 0.65
KindMethod · 0.65

Used in the wild real call sites across dependent graphs

searching dependent graphs…