Skip to content

[rust] complete extension hooks - #1501

Merged
bgentry merged 1 commit into
masterfrom
bg/plugin-peer-work-hooks
Oct 25, 2026
Merged

bgentry merged 1 commit into
masterfrom
bg/plugin-peer-work-hooks

Conversation

@bgentry

@bgentry bgentry commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

An extension that coordinates peer jobs works each peer itself, so the client's work hooks never run for peers. That includes hooks that decode job arguments. Insertion extensions also need resolved options in insert hooks, and they need to see unique duplicates after an insertion returns an existing row.

This adds PeerAttempts::work_begin and work_end to the unstable extension module. They run the client's hooks in registration order and stop at the first failing begin hook, as the executor does. Errors keep their original type through hooks and outcomes, so hooks and the error handler can downcast them. A JobCancelError in a peer's error cancels the peer, as it does for a job whose worker returns it. The executor's own begin-hook errors also skip the extra wrapper now.

The internal option trait now exposes resolved insertion options. After persistence, after_jobs_inserted gets every returned row in input order, including unique duplicates. Each row comes with its requested metadata and a flag that marks an existing duplicate. An extension can then base its bookkeeping on the stored row or on the request, within the same transaction.

ProducerClaimNext::claim_at_most lets a producer session claim fewer jobs than River's limit. The limit caps the requested maximum, a zero maximum runs no query, and the continuation is consumed either way.

JavaScript already applies argument read transforms when it claims peers, so it needs no peer-hook change.

@bgentry
bgentry force-pushed the bg/plugin-peer-work-hooks branch 2 times, most recently from 8734927 to 88e8ce3 Compare October 13, 2026 14:47
@bgentry bgentry changed the title let extensions run work hooks on peer jobs Let extensions run work hooks on peer jobs Oct 13, 2026
@bgentry
bgentry force-pushed the bg/plugin-peer-work-hooks branch from 88e8ce3 to 72ee6e9 Compare October 13, 2026 14:49
@bgentry bgentry changed the title Let extensions run work hooks on peer jobs [Rust] Let extensions run work hooks on peer jobs Oct 13, 2026
@bgentry
bgentry force-pushed the bg/plugin-peer-work-hooks branch from 72ee6e9 to 1d0186f Compare October 13, 2026 23:41
@bgentry
bgentry force-pushed the bg/plugin-peer-work-hooks branch from 1d0186f to 8e1393b Compare October 25, 2026 02:55
@bgentry bgentry changed the title [Rust] Let extensions run work hooks on peer jobs [rust] complete extension insert and work hooks Oct 25, 2026
@bgentry
bgentry force-pushed the bg/plugin-peer-work-hooks branch from 8e1393b to 7f845cc Compare October 25, 2026 03:08
@bgentry bgentry changed the title [rust] complete extension insert and work hooks [rust] complete extension hooks Oct 25, 2026
An extension that coordinates peer jobs works each peer itself, so the
client's work hooks never run for peers. Add `PeerAttempts::work_begin`
and `work_end`. They run the hooks in registration order and stop at the
first failing begin hook, as the executor does.

Keep the original error through hooks and outcomes. A boxed `WorkError`
is reused instead of wrapped again, so hooks and the error handler can
downcast the worker's error. A `JobCancelError` in a peer's error now
cancels the peer, as it cancels a job a worker returns it from.

Insertion extensions need resolved options in insert hooks and must see
unique duplicates after persistence. Expose resolved options through the
internal option trait. Pass every returned row to `after_jobs_inserted`
in input order, with its requested metadata and a flag that marks
existing duplicates.

Add `ProducerClaimNext::claim_at_most`, so a producer session can claim
fewer jobs than River's limit. The limit caps the requested maximum. A
zero maximum runs no query. The continuation is consumed either way.
@bgentry
bgentry force-pushed the bg/plugin-peer-work-hooks branch from 7f845cc to 0f7edd7 Compare October 25, 2026 18:25
@bgentry
bgentry marked this pull request as ready for review October 25, 2026 18:30
@bgentry
bgentry merged commit 1005734 into master Oct 25, 2026
36 checks passed
@bgentry
bgentry deleted the bg/plugin-peer-work-hooks branch October 25, 2026 18:36
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.

2 participants