Skip to content

Commit 03f614c

Browse files
committed
More playground architecture changes
1 parent 7ad5933 commit 03f614c

4 files changed

Lines changed: 26 additions & 19 deletions

File tree

playground/entrypoint.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/unpackdev/fdb/pkg/rbac"
1111
"github.com/unpackdev/fdb/pkg/shutdown"
1212
"github.com/unpackdev/fdb/pkg/types"
13+
"github.com/unpackdev/fdb/playground/registry"
1314
"github.com/unpackdev/fdb/playground/strategies"
1415
"github.com/unpackdev/fdb/playground/suite"
1516
"github.com/urfave/cli/v2"
@@ -73,7 +74,7 @@ func Run(cliCtx *cli.Context, cfg Config) error {
7374
shutdownMgr.Start()
7475

7576
// Create the strategy registry
76-
registry := NewRegistry(testLogger)
77+
registry := registry.New(testLogger)
7778

7879
// Register all available strategies
7980
registry.RegisterAll()
@@ -171,6 +172,6 @@ func Run(cliCtx *cli.Context, cfg Config) error {
171172
testLogger.Error("Shutdown completed with errors", "error", err.Error())
172173
}
173174

174-
testLogger.Info("Playground shutdown complete. Cause: %s", "cause", shutdownMgr.ShutdownCause())
175+
testLogger.Info("Playground shutdown complete.", "cause", shutdownMgr.ShutdownCause())
175176
return nil
176177
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package playground
1+
package registry
22

33
import (
44
"context"
@@ -23,8 +23,8 @@ type Registry struct {
2323
logger logger.Logger
2424
}
2525

26-
// NewRegistry creates a new strategy registry
27-
func NewRegistry(logger logger.Logger) *Registry {
26+
// New creates a new strategy registry
27+
func New(logger logger.Logger) *Registry {
2828
return &Registry{
2929
logger: logger,
3030
strategies: make(map[string]strategyEntry),
@@ -107,10 +107,10 @@ func (r *Registry) CreateStrategy(name string, logger logger.Logger, nodes suite
107107
return entry.Strategy.CreateFn()(logger, nodes, mergedArgs)
108108
}
109109

110-
// RegisterAll registers all available strategies from the strategies package
110+
// RegisterAll registers all available strategies from the registry package
111111
func (r *Registry) RegisterAll() {
112112
// Register all strategies from the centralized map
113-
for name, factory := range strategies.AvailableStrategies {
113+
for name, factory := range AvailableStrategies {
114114
// Create a prototype instance using the factory
115115
strategy := factory(r.logger)
116116

@@ -144,7 +144,7 @@ func (r *Registry) RunStrategy(ctx context.Context, name string, logger logger.L
144144
case <-ctx.Done():
145145
// External cancellation (shutdown manager)
146146
logger.Info("Strategy stopping due to context cancellation")
147-
147+
148148
case <-completionCh:
149149
// Strategy has completed naturally
150150
logger.Info("Strategy completed its work successfully")

playground/registry/strategies.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package registry
2+
3+
import (
4+
"github.com/unpackdev/fdb/pkg/logger"
5+
"github.com/unpackdev/fdb/playground/strategies"
6+
)
7+
8+
// RegistryFn is a function that creates a strategy prototype
9+
type RegistryFn func(logger logger.Logger) strategies.Strategy
10+
11+
// AvailableStrategies is a map of all available strategies and their factory functions
12+
// Add new strategies to this map to make them available in the playground
13+
var AvailableStrategies = map[string]RegistryFn{
14+
"write": func(logger logger.Logger) strategies.Strategy {
15+
return strategies.NewWriteStrategy(logger, nil) // Nodes will be provided later
16+
},
17+
}

playground/strategies/strategies.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,3 @@ func ParseCliArgs(cliCtx *cli.Context, info Info) map[string]any {
9696

9797
return args
9898
}
99-
100-
// StrategyFactory is a function that creates a strategy prototype
101-
type StrategyFactory func(logger logger.Logger) Strategy
102-
103-
// AvailableStrategies is a map of all available strategies and their factory functions
104-
// Add new strategies to this map to make them available in the playground
105-
var AvailableStrategies = map[string]StrategyFactory{
106-
"write": func(logger logger.Logger) Strategy {
107-
return NewWriteStrategy(logger, nil) // Nodes will be provided later
108-
},
109-
}

0 commit comments

Comments
 (0)