-
Notifications
You must be signed in to change notification settings - Fork 642
Open
Description
There are use-cases for wrapping the executions of individual query attempts.
We currently have QueryObserver and BatchObserver that allow observing the query attempts, but don't allow modification of behavior.
One use case that requires modification of behavior is a request rate limiter (#1756) or a semaphore to limit request concurrency.
It seems that instead of adding an individual interface for each use case, a single interceptor-like interface could serve all of them.
The following QueryAttemptInterceptor could be used to implement the rate limiter, however we will need to make changes the interface to be able to replace the QueryObserver and BatchObserver:
type QueryAttemptInterceptor interface {
// AttemptQuery executes the query on the given connection.
// The attempt function does the actual work, the AttempQuery implementation is free to execute code
// before/after the call to the attempt function or skip the call altogether.
// If error is nil, the returned *Iter must be non-nil.
AttemptQuery(ctx context.Context, query ExecutableQuery, conn *Conn, attempt func(ctx context, query ExecutableQuery, conn *Conn) *Iter) (*Iter, error))
}
testisnullus and RostislavPorohnya
Metadata
Metadata
Assignees
Labels
No labels