Skip to content

Commit

Permalink
Remove context from struct #4878
Browse files Browse the repository at this point in the history
ref DEV-321
  • Loading branch information
tung2744 authored Nov 11, 2024
2 parents b6c0cf3 + 706a8ac commit 18f6533
Show file tree
Hide file tree
Showing 911 changed files with 15,929 additions and 18,144 deletions.
24 changes: 12 additions & 12 deletions cmd/authgear/background/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,37 +61,37 @@ type AccountDeletionServiceFactory struct {
BackgroundProvider *deps.BackgroundProvider
}

func (f *AccountDeletionServiceFactory) MakeUserService(ctx context.Context, appID string, appContext *config.AppContext) accountdeletion.UserService {
return newUserService(ctx, f.BackgroundProvider, appID, appContext)
func (f *AccountDeletionServiceFactory) MakeUserService(appID string, appContext *config.AppContext) accountdeletion.UserService {
return newUserService(f.BackgroundProvider, appID, appContext)
}

type AccountAnonymizationServiceFactory struct {
BackgroundProvider *deps.BackgroundProvider
}

func (f *AccountAnonymizationServiceFactory) MakeUserService(ctx context.Context, appID string, appContext *config.AppContext) accountanonymization.UserService {
return newUserService(ctx, f.BackgroundProvider, appID, appContext)
func (f *AccountAnonymizationServiceFactory) MakeUserService(appID string, appContext *config.AppContext) accountanonymization.UserService {
return newUserService(f.BackgroundProvider, appID, appContext)
}

type UserFacade interface {
DeleteFromScheduledDeletion(userID string) error
AnonymizeFromScheduledAnonymization(userID string) error
DeleteFromScheduledDeletion(ctx context.Context, userID string) error
AnonymizeFromScheduledAnonymization(ctx context.Context, userID string) error
}

type UserService struct {
AppDBHandle *appdb.Handle
UserFacade UserFacade
}

func (s *UserService) DeleteFromScheduledDeletion(userID string) (err error) {
return s.AppDBHandle.WithTx(func() error {
return s.UserFacade.DeleteFromScheduledDeletion(userID)
func (s *UserService) DeleteFromScheduledDeletion(ctx context.Context, userID string) (err error) {
return s.AppDBHandle.WithTx(ctx, func(ctx context.Context) error {
return s.UserFacade.DeleteFromScheduledDeletion(ctx, userID)
})
}

func (s *UserService) AnonymizeFromScheduledAnonymization(userID string) (err error) {
return s.AppDBHandle.WithTx(func() error {
return s.UserFacade.AnonymizeFromScheduledAnonymization(userID)
func (s *UserService) AnonymizeFromScheduledAnonymization(ctx context.Context, userID string) (err error) {
return s.AppDBHandle.WithTx(ctx, func(ctx context.Context) error {
return s.UserFacade.AnonymizeFromScheduledAnonymization(ctx, userID)
})
}

Expand Down
9 changes: 5 additions & 4 deletions cmd/authgear/background/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@ func (c *Controller) Start() {
// From now, we should use c.logger to log.
c.logger = p.LoggerFactory.New("background")

configSrcController := newConfigSourceController(p, context.Background())
err = configSrcController.Open()
ctx := context.Background()
configSrcController := newConfigSourceController(p)
err = configSrcController.Open(ctx)
if err != nil {
c.logger.WithError(err).Fatal("cannot open configuration")
}
defer configSrcController.Close()

runners := []*backgroundjob.Runner{
newAccountDeletionRunner(p, context.Background(), configSrcController),
newAccountAnonymizationRunner(p, context.Background(), configSrcController),
newAccountDeletionRunner(p, configSrcController),
newAccountAnonymizationRunner(p, configSrcController),
}
backgroundjob.Main(c.logger, runners)
}
10 changes: 4 additions & 6 deletions cmd/authgear/background/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
package background

import (
"context"

"github.com/google/wire"

"github.com/authgear/authgear-server/pkg/lib/config"
Expand All @@ -16,7 +14,7 @@ import (
"github.com/authgear/authgear-server/pkg/util/backgroundjob"
)

func newConfigSourceController(p *deps.BackgroundProvider, c context.Context) *configsource.Controller {
func newConfigSourceController(p *deps.BackgroundProvider) *configsource.Controller {
panic(wire.Build(
DependencySet,
configsource.NewResolveAppIDTypeDomain,
Expand All @@ -25,23 +23,23 @@ func newConfigSourceController(p *deps.BackgroundProvider, c context.Context) *c
))
}

func newAccountAnonymizationRunner(p *deps.BackgroundProvider, c context.Context, ctrl *configsource.Controller) *backgroundjob.Runner {
func newAccountAnonymizationRunner(p *deps.BackgroundProvider, ctrl *configsource.Controller) *backgroundjob.Runner {
panic(wire.Build(
DependencySet,
accountanonymization.DependencySet,
wire.Bind(new(accountanonymization.AppContextResolver), new(*configsource.Controller)),
))
}

func newAccountDeletionRunner(p *deps.BackgroundProvider, c context.Context, ctrl *configsource.Controller) *backgroundjob.Runner {
func newAccountDeletionRunner(p *deps.BackgroundProvider, ctrl *configsource.Controller) *backgroundjob.Runner {
panic(wire.Build(
DependencySet,
accountdeletion.DependencySet,
wire.Bind(new(accountdeletion.AppContextResolver), new(*configsource.Controller)),
))
}

func newUserService(ctx context.Context, p *deps.BackgroundProvider, appID string, appContext *config.AppContext) *UserService {
func newUserService(p *deps.BackgroundProvider, appID string, appContext *config.AppContext) *UserService {
panic(wire.Build(
DependencySet,
wire.FieldsOf(new(*config.AppContext), "Config"),
Expand Down
52 changes: 20 additions & 32 deletions cmd/authgear/background/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions cmd/authgear/cmd/cmdaudit/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,14 @@ var cmdAuditDatabaseDump = &cobra.Command{
}

dumper := dbutil.NewDumper(
cmd.Context(),
dbURL,
dbSchema,
outputDir,
args,
tableNames,
)

return dumper.Dump()
return dumper.Dump(cmd.Context())
},
}

Expand All @@ -256,14 +255,13 @@ var cmdAuditDatabaseRestore = &cobra.Command{
}

restorer := dbutil.NewRestorer(
cmd.Context(),
dbURL,
dbSchema,
inputDir,
args,
tableNames,
)

return restorer.Restore()
return restorer.Restore(cmd.Context())
},
}
6 changes: 2 additions & 4 deletions cmd/authgear/cmd/cmddatabase/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,14 @@ var cmdDump = &cobra.Command{
}

dumper := dbutil.NewDumper(
cmd.Context(),
dbURL,
dbSchema,
outputDir,
args,
tableNames,
)

return dumper.Dump()
return dumper.Dump(cmd.Context())
},
}

Expand All @@ -221,14 +220,13 @@ var cmdRestore = &cobra.Command{
}

restorer := dbutil.NewRestorer(
cmd.Context(),
dbURL,
dbSchema,
inputDir,
args,
tableNames,
)

return restorer.Restore()
return restorer.Restore(cmd.Context())
},
}
Loading

0 comments on commit 18f6533

Please sign in to comment.