chore(poller): Add poller package

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu
2022-08-14 10:34:19 +08:00
committed by Jason Song
parent 4d7ef95d40
commit 0b885c5e5f
5 changed files with 107 additions and 2 deletions

View File

@ -29,6 +29,13 @@ type (
Environ map[string]string `envconfig:"GITEA_RUNNER_ENVIRON"`
EnvFile string `envconfig:"GITEA_RUNNER_ENV_FILE"`
}
Platform struct {
OS string `envconfig:"GITEA_PLATFORM_OS" default:"linux"`
Arch string `envconfig:"GITEA_PLATFORM_ARCH" default:"amd64"`
Kernel string `envconfig:"GITEA_PLATFORM_KERNEL"`
Variant string `envconfig:"GITEA_PLATFORM_VARIANT"`
}
}
)

View File

@ -6,6 +6,8 @@ import (
"gitea.com/gitea/act_runner/client"
"gitea.com/gitea/act_runner/engine"
"gitea.com/gitea/act_runner/poller"
"golang.org/x/sync/errgroup"
"github.com/joho/godotenv"
log "github.com/sirupsen/logrus"
@ -196,7 +198,27 @@ func runDaemon(ctx context.Context, input *Input) func(cmd *cobra.Command, args
}
}
return nil
var g errgroup.Group
poller := poller.New(cli)
g.Go(func() error {
log.WithField("capacity", cfg.Runner.Capacity).
WithField("endpoint", cfg.Client.Address).
WithField("os", cfg.Platform.OS).
WithField("arch", cfg.Platform.Arch).
Infoln("polling the remote server")
poller.Poll(ctx, cfg.Runner.Capacity)
return nil
})
err = g.Wait()
if err != nil {
log.WithError(err).
Errorln("shutting down the server")
}
return err
// var conn *websocket.Conn
// var err error
// ticker := time.NewTicker(time.Second)