river icon indicating copy to clipboard operation
river copied to clipboard

River Args Uniqueness Not Working

Open assembly-deepali opened this issue 1 month ago • 2 comments

I have these two payloads that I'm passing into river, and because of my custom uniqueness constraints, I don't want to be adding both of them in. But it still is, am I missing something?

Followed this format: https://pkg.go.dev/github.com/riverqueue/river#example-package-UniqueJob and am using https://riverqueue.com/docs/unique-jobs (custom unique job args)

type SyncPayload struct {
	ParentPayload
	SyncName        string `json:"syncName" river:"unique"`
	Model           string `json:"model"`
	ResponseResults struct {
		Added   int `json:"added"`
		Updated int `json:"updated"`
		Deleted int `json:"deleted"`
	} `json:"responseResults"`
	SyncType      nango.SyncType `json:"syncType" river:"unique"`
	ModifiedAfter string         `json:"modifiedAfter"`
}

type NangoSyncArgs struct {
	OrgID       string      `json:"org_id" river:"unique"`
	Payload     SyncPayload `json:"payload"`
	SlackTeamId string      `json:"slack_team_id"`
	NextCursor  *string     `json:"next_cursor,omitempty" river:"unique"`
}

// Kind implements river.JobArgs.
func (NangoSyncArgs) Kind() string {
	return "NangoSyncArgs"
}

func (a NangoSyncArgs) InsertOpts() river.InsertOpts {
	return river.InsertOpts{
		MaxAttempts: 5,
		Tags:        []string{fmt.Sprintf("org_id: %s", a.OrgID)},
		Queue:       GetCorrectCRMSyncWorkerQueue(a.Payload.SyncType == nango.InitialSync),
		UniqueOpts:  river.UniqueOpts{ByArgs: true},
	}
}
{
  "org_id": "1",
  "payload": {
    "from": "nango",
    "type": "sync",
    "model": "Account",
    "syncName": "accounts",
    "syncType": "INCREMENTAL",
    "connectionId": "a",
    "modifiedAfter": "2025-11-11T22:15:04.779Z",
    "responseResults": {
      "added": 0,
      "deleted": 0,
      "updated": 1
    },
    "providerConfigKey": "salesforce"
  },
  "next_cursor": "matching cursor",
  "slack_team_id": "a"
}

{
  "org_id": "1",
  "payload": {
    "from": "nango",
    "type": "sync",
    "model": "Account",
    "syncName": "accounts",
    "syncType": "INCREMENTAL",
    "connectionId": "a",
    "modifiedAfter": "2025-11-12T02:50:04.953Z",
    "responseResults": {
      "added": 0,
      "deleted": 0,
      "updated": 5
    },
    "providerConfigKey": "salesforce"
  },
  "next_cursor": "matching cursor",
  "slack_team_id": "a"
}

assembly-deepali avatar Nov 12 '25 17:11 assembly-deepali

It doesn't look like unique annotations on substruct fields work as you'd expected right now. Opened #1076 with a fix.

brandur avatar Nov 13 '25 04:11 brandur

Whoops, yeah I wasn't sure if people even needed this when rewriting the unique jobs implementation and never got around to getting back to implement it. Sorry about that!

Looks like @brandur already has it covered and this should be part of the next release :shipit:

bgentry avatar Nov 14 '25 02:11 bgentry