Skip to content

Navigation Menu

Sign in
Sign up

[Feature Request] Support Deadline parameter for batch job gathering in riverbatch.WorkerOpts #1266

janblaha-arenko started this conversation in Ideas
Discussion options

TLDR:

I have a scenario where I need a batch of jobs to be worked no later than x (which is dynamic). The current MaxDelay (time.Duration) parameter makes this slightly awkward as we need to calculate the MaxDelay based on a diff with time.Now. I believe a more ergonomic way of implementing such logic would be for River to support a Deadline (time.Time) parameter with basically the existing logic.

Details:

Currently, the Batching feature in RiverPro supports a MaxDelay argument which represents the "maximum amount of time to wait for a full batch with MaxCount jobs to be available" (documentation).

It is currently possible to implement a sort of "deadline" in the worker Work function which calls riverbatch.Work with riverbatch.WorkerOpts. In the work function it is possible to compute something like the following:

func (w *MyWorker) Work(ctx context.Context, job *river.Job[MyBatchArgs]) error {
 // some logic to determine deadline
 // ...
 
 // example deadline
 deadline := time.Date(2026, 6, 1, 13, 0, 0, 0, time.UTC)
 
 maxDelay := time.Until(deadline)
 return riverbatch.Work[MyBatchArgs, pgx.Tx](ctx, job, w, &riverbatch.WorkerOpts{
 MaxDelay: maxDelay
 })
}

However, I believe it would be beneficial if the WorkerOpts supported this directly with a new Deadline option. The two (MaxDelay and Deadline) could be made exclusive or falling back to one or the other when both are present. In terms of implementation I believe it should be fairly simple - just a ticker in a new case statement.

You must be logged in to vote

Replies: 1 comment

Comment options

This seems to make sense — and would mirror the context.WithTimeout / context.WithDeadline API somewhat nicely.

@bgentry Can you comment on this one before I try do to anything?

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet

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