Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ linters:
- "whitespace"
- "unused"
settings:
govet:
disable:
# inline reports spurious "cannot inline: type parameter inference is
# not yet supported" errors on calls to generic stdlib functions.
- "inline"
staticcheck:
checks:
- "all"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/authzed/controller-idioms
go 1.25.0

require (
github.com/authzed/ctxkey v0.0.0-20260210154927-ca132876f62c
github.com/authzed/ctxkey v0.1.0
github.com/cespare/xxhash/v2 v2.3.0
github.com/davecgh/go-spew v1.1.1
github.com/fsnotify/fsnotify v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cq
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ=
github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw=
github.com/authzed/ctxkey v0.0.0-20260210154927-ca132876f62c h1:kcjpI9wcj5yFYWJ7bEeiY6hqH2I6Es3lVz6PB7RKblQ=
github.com/authzed/ctxkey v0.0.0-20260210154927-ca132876f62c/go.mod h1:ve6DXRv9l2HcM2lxSUmZKWXl7Iq/00xYixBuHOtST+4=
github.com/authzed/ctxkey v0.1.0 h1:wtQnpKgjzxF//qotuiR/Toh691lbY2ZFynsQFQ57mrA=
github.com/authzed/ctxkey v0.1.0/go.mod h1:ve6DXRv9l2HcM2lxSUmZKWXl7Iq/00xYixBuHOtST+4=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
Expand Down
55 changes: 10 additions & 45 deletions queue/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,37 +57,33 @@ import (
"github.com/authzed/controller-idioms/state"
)

// Done creates a handler that marks the current queue key as finished and terminates the pipeline.
// Done is a handler that marks the current queue key as finished and terminates the pipeline.
// This is equivalent to calling queue.NewQueueOperationsCtx().Done(ctx) and returning.
//
// Usage:
//
// pipeline := state.Sequence(
// validateInput,
// processResource,
// queue.Done(), // Stop here - processing complete
// queue.Done, // Stop here - processing complete
// )
func Done() state.NewStep {
return state.NewTerminalStepFunc(func(ctx context.Context) {
NewQueueOperationsCtx().Done(ctx)
})
}
var Done = state.NewTerminalStepFunc(func(ctx context.Context) {
NewQueueOperationsCtx().Done(ctx)
})

// Requeue creates a handler that requeues the current key immediately and terminates the pipeline.
// Requeue is a handler that requeues the current key immediately and terminates the pipeline.
// This is equivalent to calling queue.NewQueueOperationsCtx().Requeue(ctx) and returning.
//
// Usage:
//
// pipeline := state.Decision(
// resourceReady,
// continueProcessing,
// queue.Requeue(), // Not ready - try again immediately
// queue.Requeue, // Not ready - try again immediately
// )
func Requeue() state.NewStep {
return state.NewTerminalStepFunc(func(ctx context.Context) {
NewQueueOperationsCtx().Requeue(ctx)
})
}
var Requeue = state.NewTerminalStepFunc(func(ctx context.Context) {
NewQueueOperationsCtx().Requeue(ctx)
})

// RequeueAfter creates a handler that requeues the current key after the specified duration
// and terminates the pipeline.
Expand Down Expand Up @@ -160,34 +156,3 @@ func RequeueAPIErr(err error) state.NewStep {
NewQueueOperationsCtx().RequeueAPIErr(ctx, err)
})
}

// OnError creates a handler that executes different queue operations based on whether
// an error occurred in the context.
//
// Usage:
//
// pipeline := state.Sequence(
// riskyOperation,
// queue.OnError(
// queue.RequeueErr(fmt.Errorf("operation failed")), // If error
// queue.Done(), // If success
// ),
// )
func OnError(errorHandler, successHandler state.NewStep) state.NewStep {
return func(next state.Step) state.Step {
errStep := errorHandler(next)
okStep := successHandler(next)
return state.StepFunc(func(ctx context.Context) state.Step {
if ctx.Err() != nil {
if errStep != nil {
return errStep.Run(ctx)
}
return nil
}
if okStep != nil {
return okStep.Run(ctx)
}
return nil
})
}
}
Loading
Loading