Skip to content

Navigation Menu

Sign in
Sign up

Let job args return plugins like they can for hooks/middleware - #1337

Merged
brandur merged 1 commit into
master from
brandur-job-plugins
Jul 31, 2026
Merged

Let job args return plugins like they can for hooks/middleware #1337
brandur merged 1 commit into
master from
brandur-job-plugins

Conversation

@brandur

@brandur brandur commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Here, implement a job args jobArgsWithPlugins interface that lets job
args return a set of Plugins. This follows up the addition of plugins
in #1284, and makes the functionality symmetrical to what's available
with hooks/middleware. I would have done this before, but I forgot that
you could do this until I was looking at docs today. As in #1284 for
client config, Hooks and Middleware continue to be supported on job
args and have not yet been deprecated.

type EmailArgs struct {
 To string `json:"to"`
}
func (EmailArgs) Kind() string { return "email" }
func (EmailArgs) Plugins() []rivertype.Plugin {
 return []rivertype.Plugin{
 &EmailPlugin{},
 }
}
type EmailPlugin struct {
 river.PluginDefaults
}
func (p *EmailPlugin) WorkBegin(ctx context.Context, job *rivertype.JobRow) error {
 return nil
}

I also had Codex look for opportunities for implementation clean up
since all of this was feeling like a few too many LOCs. It was able to
clean up ~85 LOCs net, with the main change being to get rid of
PluginLookupInterface + emptyPluginLookup. This removes a layer of
indirection, which is good, but also emptyPluginLookup had become less
useful due to River installing default middleware (ResumableMiddleware)
on all clients whether any has been specified by a client or not.

Here, implement a job args `jobArgsWithPlugins` interface that lets job
args return a set of `Plugins`. This follows up the addition of plugins
in #1284, and makes the functionality symmetrical to what's available
with hooks/middleware. I would have done this before, but I forgot that
you could do this until I was looking at docs today. As in #1284 for
client config, `Hooks` and `Middleware` continue to be supported on job
args and have not yet been deprecated.
 type EmailArgs struct {
 To string `json:"to"`
 }
 func (EmailArgs) Kind() string { return "email" }
 func (EmailArgs) Plugins() []rivertype.Plugin {
 return []rivertype.Plugin{
 &EmailPlugin{},
 }
 }
 type EmailPlugin struct {
 river.PluginDefaults
 }
 func (p *EmailPlugin) WorkBegin(ctx context.Context, job *rivertype.JobRow) error {
 return nil
 }
I also had Codex look for opportunities for implementation clean up
since all of this was feeling like a few too many LOCs. It was able to
clean up ~85 LOCs net, with the main change being to get rid of
`PluginLookupInterface` + `emptyPluginLookup`. This removes a layer of
indirection, which is good, but also `emptyPluginLookup` had become less
useful due to River installing default middleware (`ResumableMiddleware`)
on all clients whether any has been specified by a client or not.

brandur commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

Thx!

brandur merged commit 1c38b9d into master Jul 31, 2026
15 checks passed
brandur deleted the brandur-job-plugins branch July 31, 2026 19:19
brandur added a commit that referenced this pull request Jul 31, 2026
Just a small release for #1337. I added a few docs recently that
reference some changes in that pull request so want to make sure that it
gets out the door in a relatively timely manner.
[skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@bgentry bgentry bgentry approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle によって変換されたページ (->オリジナル) /