Use strong typing and allow atomic change of the max runners (#24)
* Use strong typing and allow atomic change of the max runners * prepare type change in dockerscaleset
This commit is contained in:
@@ -12,8 +12,8 @@ import (
|
||||
|
||||
type Config struct {
|
||||
RegistrationURL string
|
||||
MaxRunners int
|
||||
MinRunners int
|
||||
MaxRunners uint32
|
||||
MinRunners uint32
|
||||
ScaleSetName string
|
||||
RunnerGroup string
|
||||
GitHubApp scaleset.GitHubAppAuth
|
||||
|
||||
@@ -19,8 +19,8 @@ import (
|
||||
func init() {
|
||||
flags := cmd.Flags()
|
||||
flags.StringVar(&cfg.RegistrationURL, "url", "", "REQUIRED: URL where to register your scale set (e.g. https://github.com/org/repo)")
|
||||
flags.IntVar(&cfg.MaxRunners, "max-runners", 10, "Maximum number of runners")
|
||||
flags.IntVar(&cfg.MinRunners, "min-runners", 0, "Minimum number of runners")
|
||||
flags.Uint32Var(&cfg.MaxRunners, "max-runners", 10, "Maximum number of runners")
|
||||
flags.Uint32Var(&cfg.MinRunners, "min-runners", 0, "Minimum number of runners")
|
||||
flags.StringVar(&cfg.ScaleSetName, "name", "", "REQUIRED: Name of your scale set")
|
||||
flags.StringVar(&cfg.RunnerGroup, "runner-group", scaleset.DefaultRunnerGroup, "Name of the runner group your scale set should belong to")
|
||||
flags.StringVar(&cfg.GitHubApp.ClientID, "app-client-id", "", "GitHub App client id")
|
||||
@@ -140,8 +140,8 @@ func run(ctx context.Context, c Config) error {
|
||||
logger.Info("Initializing listener")
|
||||
listener, err := listener.New(scalesetClient, listener.Config{
|
||||
ScaleSetID: scaleSet.ID,
|
||||
MinRunners: c.MinRunners,
|
||||
MaxRunners: c.MaxRunners,
|
||||
MinRunners: int(c.MinRunners),
|
||||
MaxRunners: int(c.MaxRunners),
|
||||
Logger: logger.WithGroup("listener"),
|
||||
})
|
||||
if err != nil {
|
||||
@@ -158,7 +158,7 @@ func run(ctx context.Context, c Config) error {
|
||||
minRunners: c.MinRunners,
|
||||
dockerClient: dockerClient,
|
||||
scalesetClient: scalesetClient,
|
||||
scaleSetID: scaleSet.ID,
|
||||
scaleSetID: uint64(scaleSet.ID),
|
||||
}
|
||||
|
||||
defer scaler.shutdown(context.WithoutCancel(ctx))
|
||||
|
||||
@@ -16,16 +16,16 @@ import (
|
||||
type Scaler struct {
|
||||
runners runnerState
|
||||
runnerImage string
|
||||
scaleSetID int
|
||||
scaleSetID uint64
|
||||
dockerClient *dockerclient.Client
|
||||
scalesetClient *scaleset.Client
|
||||
minRunners int
|
||||
minRunners uint32
|
||||
logger *slog.Logger
|
||||
}
|
||||
|
||||
func (a *Scaler) HandleDesiredRunnerCount(ctx context.Context, count int) (int, error) {
|
||||
currentCount := a.runners.count()
|
||||
targetRunnerCount := min(a.minRunners + count)
|
||||
targetRunnerCount := min(int(a.minRunners) + count)
|
||||
|
||||
switch {
|
||||
case targetRunnerCount == currentCount:
|
||||
|
||||
Reference in New Issue
Block a user