feat(core): the client running a job is available from its context - #27
Merged
Merged
Conversation
giraffesyo
enabled auto-merge (squash)
October 1, 2026 02:50
giraffesyo
disabled auto-merge
October 1, 2026 02:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
From the API review of hopper's two real users.
The seam. Workers are registered before the client that runs them exists, and a component that both registers workers and needs the client, to insert follow-up jobs from a subscriber or a worker, has nowhere to get it. One user resolves this with a
Bind(client)step after construction and a nil check in every handler; the other has not hit it yet because its only job is a no-op.The change.
hopper.ClientFromContext[TTx](ctx)returns the client running the job whose context this is, andfalseoutside a job or for another transaction type.executeputs the client in the job context next to the output holder, so workers and subscribers (which run as jobs) both get it.hopper.ContextWithClient(ctx, client)builds such a context, for tests that call a worker inline withhoppertest.Work.hoppertest.Start(ctx, t, client)starts a client and stops it at test end with a context that outlives the test's, which both users' tests wrote by hand.Tests. A worker and a subscriber insert follow-ups through the context's client; a plain context and a mismatched transaction type return
false;hoppertest.Workwith and withoutContextWithClient. Full suite passes locally with-race; lint clean.Considered and left out. A
Config.MaxWorkersshortcut for the default queue: both users write the one-entryQueuesmap, but a second way to say the same thing is not worth it.PLAN.md §4.1 and the README describe the accessor. No SQL or hot-path change, so no benchmark.