Skip to content

Add helper for job metadata updates#1269

Merged
brandur merged 16 commits into
riverqueue:masterfrom
peter941221:peter/1218-set-metadata-helper
Jun 3, 2026
Merged

Add helper for job metadata updates#1269
brandur merged 16 commits into
riverqueue:masterfrom
peter941221:peter/1218-set-metadata-helper

Conversation

@peter941221
Copy link
Copy Markdown
Contributor

@peter941221 peter941221 commented Jun 2, 2026

  1. Adds a small public SetMetadata(ctx, key, value) helper for writing metadata updates onto the existing work-context merge path.
  2. Keeps the surface intentionally narrow: no batch API, no delete API, no hook signature changes, and no completion semantics changes.
  3. Rejects river:-prefixed keys so user code can't collide with River-reserved metadata keys.
  4. Adds focused coverage for the helper contract itself plus worker and HookWorkEnd integration paths.

Closes #1218.

Verification:

  1. go test ./... -run "TestSetMetadata|Test_Client_Common/(WithWorkerSettingMetadata|WithWorkEndHookSettingMetadata)" -count=1
  2. make test

@peter941221 peter941221 marked this pull request as ready for review June 2, 2026 03:59
Copy link
Copy Markdown
Contributor

@brandur brandur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Seems useful. I like the touch that we reject use of the river:* namespace.

Comment thread cmd/river/rivercli/river_cli_test.go Outdated
Comment thread worker.go
Comment thread client_test.go
Comment thread metadata.go Outdated
@peter941221
Copy link
Copy Markdown
Contributor Author

Thanks. I dropped the unrelated CLI and worker.go changes, scoped the test-only job args into the test case, and normalized the error message casing.

@peter941221
Copy link
Copy Markdown
Contributor Author

One note on the remaining red check: the retriggered run moved the failure from build_and_test (1.26, 15) to build_and_test (1.26, 14), and both failures happened during Docker pull for postgres:15 in container setup rather than during test execution, so this looks like CI flakiness rather than a code regression.\n\nLatest run: https://github.com/riverqueue/river/actions/runs/26804256615

Comment thread client_test.go
Comment thread metadata.go Outdated
@brandur
Copy link
Copy Markdown
Contributor

brandur commented Jun 2, 2026

@peter941221 Was just thinking about this a bit more today, and could you rename GetMetadata to MetadataGet?

It's a bit more of a mouthful, but since this is a top-level package function, using a Metadata* prefix means it'll stay sorted with alike functions if we end up adding more functions later (e.g. MetadataClear, MetadataDelete, or something like that).

It's also consistent with how things are named on Client like JobGet vs. JobList.

@peter941221
Copy link
Copy Markdown
Contributor Author

Renamed the helper to MetadataSet in d8e114f so the top-level metadata helpers stay grouped under Metadata*.

@brandur
Copy link
Copy Markdown
Contributor

brandur commented Jun 3, 2026

@peter941221 Great, thanks! Okay, this is looking good. Can you add a CHANGELOG entry? Put it under the "added' section.

@peter941221
Copy link
Copy Markdown
Contributor Author

Added the CHANGELOG entry under Unreleased -> Added in c0e0902.

@peter941221
Copy link
Copy Markdown
Contributor Author

The red check was another windows-latest postgres bootstrap failure in action-setup-postgres before checkout or CLI execution. I pushed a no-op commit to retrigger CI on a fresh runner.

@brandur
Copy link
Copy Markdown
Contributor

brandur commented Jun 3, 2026

Thanks! Yeah, we definitely have a couple GItHub Actions-related flakes going on.

@brandur brandur merged commit dfc32de into riverqueue:master Jun 3, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Official way to set keys in metadata

2 participants