Skip to content

Commit

Permalink
Merge pull request #389 from pace/routine-cancellation
Browse files Browse the repository at this point in the history
pkg/routine: Use WithoutCancel instead of Transfer
  • Loading branch information
monstermunchkin authored Dec 4, 2024
2 parents ea4131d + 6ef667c commit d6fdde5
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions pkg/routine/routine.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/getsentry/sentry-go"
"github.com/pace/bricks/maintenance/errors"
"github.com/pace/bricks/maintenance/log"
pkgcontext "github.com/pace/bricks/pkg/context"
)

type options struct {
Expand Down Expand Up @@ -82,13 +81,12 @@ func RunNamed(parentCtx context.Context, name string, routine func(context.Conte
return Run(parentCtx, routine)
}

// Run runs the given function in a new background context. The new context
// inherits the logger and oauth2 authentication of the parent context. Panics
// Run runs the given function in a new background context. Panics
// thrown in the function are logged and sent to sentry. The routines context is
// canceled if the program receives a shutdown signal (SIGINT, SIGTERM), if the
// returned CancelFunc is called, or if the routine returned.
func Run(parentCtx context.Context, routine func(context.Context)) (cancel context.CancelFunc) {
ctx := pkgcontext.Transfer(parentCtx)
func Run(ctx context.Context, routine func(context.Context)) (cancel context.CancelFunc) {
ctx = context.WithoutCancel(ctx)

// add routine number to context and logger
num := atomic.AddInt64(&ctr, 1)
Expand Down

0 comments on commit d6fdde5

Please sign in to comment.