Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

queue.Operations: add context cancelation and record error #14

Merged
merged 1 commit into from
Sep 22, 2022

Conversation

ecordell
Copy link
Contributor

This addresses an important case where a (preexisting) handler is wrapped in another handler

Canceling the context when a queue operation is performed signals to wrappers that the handler chain should stop (and also protects against accidental further processing, i.e. with a kube client)

Recording the error on the operations context (which is similar to context.Context) gives the caller a chance to do something with the error before returning.

Example:

var Queue = queue.NewQueueOperationsCtx()

func (s *Wrapper) Handle(ctx context.Context) {
	otherHandler.Handle(ctx)
        if errors.Is(ctx.Err(), context.Canceled) {
            if err := Queue.Error(ctx); err != nil {
                logger.V(2).Error(, "error calling underlying handler")
            }
            return
        }
	s.next.Handle(ctx)
}

this addresses an important case where a (preexisting) handler is
wrapped in another handler

canceling the context when a queue operation is performed signals to
wrappers that the handler chain should stop (and also protects against
accidental further processing, i.e. with a kube client)

recording the error on the operations context (which is similar to
context.Context) gives the caller a chance to do something with the
error before returning
@ecordell ecordell changed the title queue.OperationsContext: add context cancelation and record error queue.Operations: add context cancelation and record error Sep 22, 2022
@ecordell ecordell requested a review from jzelinskie September 22, 2022 14:49
@jzelinskie jzelinskie merged commit a4ba432 into authzed:main Sep 22, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Sep 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants