chore(runner): remove update runner status

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi.Wu 2022-11-19 09:10:52 +08:00 committed by Jason Song
parent 8f950ccec0
commit e9e42e850b
6 changed files with 17 additions and 106 deletions

View File

@ -3,12 +3,7 @@ package cmd
import (
"context"
"os"
"strconv"
"gitea.com/gitea/act_runner/engine"
"gitea.com/gitea/act_runner/runtime"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@ -25,16 +20,12 @@ func Execute(ctx context.Context) {
// ./act_runner
rootCmd := &cobra.Command{
Use: "act [event name to run]\nIf no event name passed, will default to \"on: push\"",
Short: "Run GitHub actions locally by specifying the event name (e.g. `push`) or an action name directly.",
Args: cobra.MaximumNArgs(1),
// RunE: runRoot(ctx, task),
Use: "act [event name to run]\nIf no event name passed, will default to \"on: push\"",
Short: "Run GitHub actions locally by specifying the event name (e.g. `push`) or an action name directly.",
Args: cobra.MaximumNArgs(1),
Version: version,
SilenceUsage: true,
}
//rootCmd.Flags().BoolP("run", "r", false, "run workflows")
//rootCmd.Flags().StringP("job", "j", "", "run job")
//rootCmd.PersistentFlags().StringVarP(&task.Input.ForgeInstance, "forge-instance", "", "github.com", "Forge instance to use.")
rootCmd.PersistentFlags().StringVarP(&gArgs.EnvFile, "env-file", "", ".env", "Read in a file of environment variables.")
// ./act_runner register
@ -69,22 +60,3 @@ func Execute(ctx context.Context) {
os.Exit(1)
}
}
func runRoot(ctx context.Context, task *runtime.Task) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
jobID, err := cmd.Flags().GetString("job")
if err != nil {
return err
}
// try to connect to docker daemon
// if failed, exit with error
if err := engine.Start(ctx); err != nil {
log.WithError(err).Fatalln("failed to connect docker daemon engine")
}
task.BuildID, _ = strconv.ParseInt(jobID, 10, 64)
_ = task.Run(ctx, nil)
return nil
}
}

View File

@ -9,9 +9,7 @@ import (
"gitea.com/gitea/act_runner/engine"
"gitea.com/gitea/act_runner/poller"
"gitea.com/gitea/act_runner/runtime"
runnerv1 "gitea.com/gitea/proto-go/runner/v1"
"github.com/bufbuild/connect-go"
"github.com/joho/godotenv"
"github.com/mattn/go-isatty"
log "github.com/sirupsen/logrus"
@ -63,41 +61,17 @@ func runDaemon(ctx context.Context, envFile string) func(cmd *cobra.Command, arg
)
g.Go(func() error {
log.WithField("capacity", cfg.Runner.Capacity).
l := 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")
WithField("arch", cfg.Platform.Arch)
l.Infoln("polling the remote server")
// update runner status to idle
log.Infoln("update runner status to idle")
if _, err := cli.UpdateRunner(
context.Background(),
connect.NewRequest(&runnerv1.UpdateRunnerRequest{
Status: runnerv1.RunnerStatus_RUNNER_STATUS_IDLE,
}),
); err != nil {
// go on, if return err, the program will be stuck
log.WithError(err).
Errorln("failed to update runner")
if err := poller.Poll(ctx); err != nil {
l.Errorf("poller error: %v", err)
}
return poller.Poll(ctx)
})
g.Go(func() error {
// wait all workflows done.
poller.Wait()
// received the shutdown signal
<-ctx.Done()
log.Infoln("update runner status to offline")
_, err := cli.UpdateRunner(
context.Background(),
connect.NewRequest(&runnerv1.UpdateRunnerRequest{
Status: runnerv1.RunnerStatus_RUNNER_STATUS_OFFLINE,
}),
)
return err
return nil
})
err = g.Wait()

View File

@ -105,7 +105,6 @@ func (r *registerInputs) validate() error {
}
func (r *registerInputs) assignToNext(stage registerStage, value string) registerStage {
// must set instance address and token.
// if empty, keep current stage.
if stage == StageInputInstance || stage == StageInputToken {
@ -141,14 +140,7 @@ func (r *registerInputs) assignToNext(stage registerStage, value string) registe
return StageUnknown
}
func getLocalConfigFile(envFile string) (string, bool) {
_ = godotenv.Load(envFile)
cfg, _ := config.FromEnviron()
return cfg.Runner.File, file.IsFile(cfg.Runner.File)
}
func registerInteractive(envFile string) error {
var (
reader = bufio.NewReader(os.Stdin)
stage = StageInputInstance
@ -236,7 +228,6 @@ func registerNoInteractive(envFile string, regArgs *registerArgs) error {
}
func doRegister(cfg *config.Config, inputs *registerInputs) error {
ctx := context.Background()
// initial http client

2
go.mod
View File

@ -3,7 +3,7 @@ module gitea.com/gitea/act_runner
go 1.18
require (
gitea.com/gitea/proto-go v0.0.0-20221028125601-35c4f6b05835
gitea.com/gitea/proto-go v0.0.0-20221118134050-62e4a9f56c7d
github.com/appleboy/com v0.1.6
github.com/avast/retry-go/v4 v4.1.0
github.com/bufbuild/connect-go v0.5.0

4
go.sum
View File

@ -25,8 +25,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
gitea.com/gitea/act v0.0.0-20221118080951-9b851be87df2 h1:9ZzHV6AYMguxU1dnKajPWOObH0Bp8n0fcK67hutUop0=
gitea.com/gitea/act v0.0.0-20221118080951-9b851be87df2/go.mod h1:lpzib6X73FHLSaTqTakan1xcsCAVhlZvPSpLns7jkRo=
gitea.com/gitea/proto-go v0.0.0-20221028125601-35c4f6b05835 h1:27PhT7Nli/pgRo1bDYVZ+hlCKuF9cfFuo+y9muaPVJY=
gitea.com/gitea/proto-go v0.0.0-20221028125601-35c4f6b05835/go.mod h1:hD8YwSHusjwjEEgubW6XFvnZuNhMZTHz6lwjfltEt/Y=
gitea.com/gitea/proto-go v0.0.0-20221118134050-62e4a9f56c7d h1:xqNMHMmgliaehWAzMtWdqL6/ThdrYLZa/wPky9XdnMU=
gitea.com/gitea/proto-go v0.0.0-20221118134050-62e4a9f56c7d/go.mod h1:hD8YwSHusjwjEEgubW6XFvnZuNhMZTHz6lwjfltEt/Y=
github.com/Azure/azure-sdk-for-go v16.2.1+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=

View File

@ -38,10 +38,6 @@ type Poller struct {
workerNum int
}
func (p *Poller) Wait() {
p.routineGroup.Wait()
}
func (p *Poller) schedule() {
p.Lock()
defer p.Unlock()
@ -55,6 +51,10 @@ func (p *Poller) schedule() {
}
}
func (p *Poller) Wait() {
p.routineGroup.Wait()
}
func (p *Poller) Poll(ctx context.Context) error {
l := log.WithField("func", "Poll")
@ -83,19 +83,6 @@ func (p *Poller) Poll(ctx context.Context) error {
break
}
// update runner status
// running: idle -> active
if val := p.metric.IncBusyWorker(); val == 1 {
if _, err := p.Client.UpdateRunner(
ctx,
connect.NewRequest(&runnerv1.UpdateRunnerRequest{
Status: runnerv1.RunnerStatus_RUNNER_STATUS_ACTIVE,
}),
); err != nil {
return err
}
l.Info("update runner status to active")
}
p.routineGroup.Run(func() {
if err := p.dispatchTask(ctx, task); err != nil {
l.Errorf("execute task: %v", err.Error())
@ -144,25 +131,12 @@ func (p *Poller) pollTask(ctx context.Context) (*runnerv1.Task, error) {
func (p *Poller) dispatchTask(ctx context.Context, task *runnerv1.Task) error {
l := log.WithField("func", "dispatchTask")
defer func() {
val := p.metric.DecBusyWorker()
p.metric.DecBusyWorker()
e := recover()
if e != nil {
l.Errorf("panic error: %v", e)
}
p.schedule()
if val != 0 {
return
}
if _, err := p.Client.UpdateRunner(
ctx,
connect.NewRequest(&runnerv1.UpdateRunnerRequest{
Status: runnerv1.RunnerStatus_RUNNER_STATUS_IDLE,
}),
); err != nil {
l.Errorln("update status error:", err.Error())
}
l.Info("update runner status to idle")
}()
runCtx, cancel := context.WithTimeout(ctx, time.Hour)