Skip to content

Commit

Permalink
dont' pass config to makeHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
korotkov-aerospike committed Dec 29, 2024
1 parent 177bfa4 commit d7511ea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
6 changes: 3 additions & 3 deletions cmd/backup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func startService(configFile string, remote bool) error {
return fmt.Errorf("failed to load configuration: %w", err)
}

appLogger := setDefaultLoggers(ctx, config)
appLogger := setDefaultLoggers(ctx, config.ServiceConfig.GetLoggerOrDefault())
slog.Info("Aerospike Backup Service", "commit", commit, "buildTime", buildTime)

// schedule all configured backups
Expand Down Expand Up @@ -121,9 +121,9 @@ func startService(configFile string, remote bool) error {
return err
}

func setDefaultLoggers(ctx context.Context, config *model.Config) *slog.Logger {
func setDefaultLoggers(ctx context.Context, loggerConfig *model.LoggerConfig) *slog.Logger {
appLogger := slog.New(
util.LogHandler(config.ServiceConfig.GetLoggerOrDefault()),
util.LogHandler(loggerConfig),
)
slog.SetDefault(appLogger)
logger.SetDefault(util.NewQuartzLogger(ctx))
Expand Down
13 changes: 6 additions & 7 deletions pkg/service/backup_routine_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,28 +97,27 @@ type BackupHandlerHolder map[string]backupRunner

// newBackupRoutineHandler returns a new BackupRoutineHandler instance.
func newBackupRoutineHandler(
config *model.Config,
clientManager aerospike.ClientManager,
backupService Backup,
routineName string,
routine *model.BackupRoutine,
backupBackend *BackupBackend,
lastRun *model.LastBackupRun,
) *BackupRoutineHandler {
backupRoutine := config.BackupRoutines[routineName]
backupPolicy := backupRoutine.BackupPolicy
backupStorage := backupRoutine.Storage
backupPolicy := routine.BackupPolicy
backupStorage := routine.Storage
logger := slog.Default().With(slog.String("routine", routineName))

return &BackupRoutineHandler{
backupService: backupService,
metadataWriter: backupBackend,
backupRoutine: backupRoutine,
backupRoutine: routine,
backupFullPolicy: backupPolicy,
backupIncrPolicy: backupPolicy.CopySMDDisabled(), // incremental backups should not contain metadata
routineName: routineName,
namespaces: backupRoutine.Namespaces,
namespaces: routine.Namespaces,
storage: backupStorage,
secretAgent: backupRoutine.SecretAgent,
secretAgent: routine.SecretAgent,
lastRun: lastRun,
retry: newRetryExecutor(
backupPolicy.GetRetryPolicyOrDefault(),
Expand Down
8 changes: 4 additions & 4 deletions pkg/service/config_applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ func makeHandlers(

var wg sync.WaitGroup
var mu sync.Mutex
for routineName := range config.BackupRoutines {
for routineName, routine := range config.BackupRoutines {
wg.Add(1)
go func() {
defer wg.Done()
handler := makeHandler(ctx, clientManager, config, backends, oldHandlers, routineName)
handler := makeHandler(ctx, clientManager, backends, oldHandlers, routineName, routine)
mu.Lock()
handlers[routineName] = handler
mu.Unlock()
Expand All @@ -114,10 +114,10 @@ func makeHandlers(
func makeHandler(
ctx context.Context,
clientManager aerospike.ClientManager,
config *model.Config,
backends BackendsHolder,
oldHandlers BackupHandlerHolder,
routineName string,
routine *model.BackupRoutine,
) *BackupRoutineHandler {
backupService := NewBackupGo()
backend, _ := backends.Get(routineName)
Expand All @@ -130,5 +130,5 @@ func makeHandler(
lastRun = backend.findLastRun(ctx) // this scan can take some time.
}

return newBackupRoutineHandler(config, clientManager, backupService, routineName, backend, lastRun)
return newBackupRoutineHandler(clientManager, backupService, routineName, routine, backend, lastRun)
}

0 comments on commit d7511ea

Please sign in to comment.