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:
Nikola Jokic
2025-11-26 12:10:39 +01:00
committed by GitHub
parent 6d1c317b90
commit 7442885c99
7 changed files with 51 additions and 61 deletions
+2 -2
View File
@@ -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
+5 -5
View File
@@ -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))
+3 -3
View File
@@ -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: