mirror of https://code.forgejo.org/forgejo/runner
chore(runner): remove update runner status
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>pull/2/head
parent
8f950ccec0
commit
e9e42e850b
28
cmd/cmd.go
28
cmd/cmd.go
|
@ -3,12 +3,7 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"gitea.com/gitea/act_runner/engine"
|
|
||||||
"gitea.com/gitea/act_runner/runtime"
|
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,13 +23,9 @@ func Execute(ctx context.Context) {
|
||||||
Use: "act [event name to run]\nIf no event name passed, will default to \"on: push\"",
|
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.",
|
Short: "Run GitHub actions locally by specifying the event name (e.g. `push`) or an action name directly.",
|
||||||
Args: cobra.MaximumNArgs(1),
|
Args: cobra.MaximumNArgs(1),
|
||||||
// RunE: runRoot(ctx, task),
|
|
||||||
Version: version,
|
Version: version,
|
||||||
SilenceUsage: true,
|
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.")
|
rootCmd.PersistentFlags().StringVarP(&gArgs.EnvFile, "env-file", "", ".env", "Read in a file of environment variables.")
|
||||||
|
|
||||||
// ./act_runner register
|
// ./act_runner register
|
||||||
|
@ -69,22 +60,3 @@ func Execute(ctx context.Context) {
|
||||||
os.Exit(1)
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -9,9 +9,7 @@ import (
|
||||||
"gitea.com/gitea/act_runner/engine"
|
"gitea.com/gitea/act_runner/engine"
|
||||||
"gitea.com/gitea/act_runner/poller"
|
"gitea.com/gitea/act_runner/poller"
|
||||||
"gitea.com/gitea/act_runner/runtime"
|
"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/joho/godotenv"
|
||||||
"github.com/mattn/go-isatty"
|
"github.com/mattn/go-isatty"
|
||||||
log "github.com/sirupsen/logrus"
|
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 {
|
g.Go(func() error {
|
||||||
log.WithField("capacity", cfg.Runner.Capacity).
|
l := log.WithField("capacity", cfg.Runner.Capacity).
|
||||||
WithField("endpoint", cfg.Client.Address).
|
WithField("endpoint", cfg.Client.Address).
|
||||||
WithField("os", cfg.Platform.OS).
|
WithField("os", cfg.Platform.OS).
|
||||||
WithField("arch", cfg.Platform.Arch).
|
WithField("arch", cfg.Platform.Arch)
|
||||||
Infoln("polling the remote server")
|
l.Infoln("polling the remote server")
|
||||||
|
|
||||||
// update runner status to idle
|
if err := poller.Poll(ctx); err != nil {
|
||||||
log.Infoln("update runner status to idle")
|
l.Errorf("poller error: %v", err)
|
||||||
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")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return poller.Poll(ctx)
|
|
||||||
})
|
|
||||||
|
|
||||||
g.Go(func() error {
|
|
||||||
// wait all workflows done.
|
|
||||||
poller.Wait()
|
poller.Wait()
|
||||||
// received the shutdown signal
|
return nil
|
||||||
<-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
|
|
||||||
})
|
})
|
||||||
|
|
||||||
err = g.Wait()
|
err = g.Wait()
|
||||||
|
|
|
@ -105,7 +105,6 @@ func (r *registerInputs) validate() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *registerInputs) assignToNext(stage registerStage, value string) registerStage {
|
func (r *registerInputs) assignToNext(stage registerStage, value string) registerStage {
|
||||||
|
|
||||||
// must set instance address and token.
|
// must set instance address and token.
|
||||||
// if empty, keep current stage.
|
// if empty, keep current stage.
|
||||||
if stage == StageInputInstance || stage == StageInputToken {
|
if stage == StageInputInstance || stage == StageInputToken {
|
||||||
|
@ -141,14 +140,7 @@ func (r *registerInputs) assignToNext(stage registerStage, value string) registe
|
||||||
return StageUnknown
|
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 {
|
func registerInteractive(envFile string) error {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
reader = bufio.NewReader(os.Stdin)
|
reader = bufio.NewReader(os.Stdin)
|
||||||
stage = StageInputInstance
|
stage = StageInputInstance
|
||||||
|
@ -236,7 +228,6 @@ func registerNoInteractive(envFile string, regArgs *registerArgs) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func doRegister(cfg *config.Config, inputs *registerInputs) error {
|
func doRegister(cfg *config.Config, inputs *registerInputs) error {
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
// initial http client
|
// initial http client
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module gitea.com/gitea/act_runner
|
||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
require (
|
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/appleboy/com v0.1.6
|
||||||
github.com/avast/retry-go/v4 v4.1.0
|
github.com/avast/retry-go/v4 v4.1.0
|
||||||
github.com/bufbuild/connect-go v0.5.0
|
github.com/bufbuild/connect-go v0.5.0
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -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=
|
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 h1:9ZzHV6AYMguxU1dnKajPWOObH0Bp8n0fcK67hutUop0=
|
||||||
gitea.com/gitea/act v0.0.0-20221118080951-9b851be87df2/go.mod h1:lpzib6X73FHLSaTqTakan1xcsCAVhlZvPSpLns7jkRo=
|
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-20221118134050-62e4a9f56c7d h1:xqNMHMmgliaehWAzMtWdqL6/ThdrYLZa/wPky9XdnMU=
|
||||||
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/go.mod h1:hD8YwSHusjwjEEgubW6XFvnZuNhMZTHz6lwjfltEt/Y=
|
||||||
github.com/Azure/azure-sdk-for-go v16.2.1+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
|
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 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8=
|
||||||
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
|
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
|
||||||
|
|
|
@ -38,10 +38,6 @@ type Poller struct {
|
||||||
workerNum int
|
workerNum int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Poller) Wait() {
|
|
||||||
p.routineGroup.Wait()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Poller) schedule() {
|
func (p *Poller) schedule() {
|
||||||
p.Lock()
|
p.Lock()
|
||||||
defer p.Unlock()
|
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 {
|
func (p *Poller) Poll(ctx context.Context) error {
|
||||||
l := log.WithField("func", "Poll")
|
l := log.WithField("func", "Poll")
|
||||||
|
|
||||||
|
@ -83,19 +83,6 @@ func (p *Poller) Poll(ctx context.Context) error {
|
||||||
break
|
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() {
|
p.routineGroup.Run(func() {
|
||||||
if err := p.dispatchTask(ctx, task); err != nil {
|
if err := p.dispatchTask(ctx, task); err != nil {
|
||||||
l.Errorf("execute task: %v", err.Error())
|
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 {
|
func (p *Poller) dispatchTask(ctx context.Context, task *runnerv1.Task) error {
|
||||||
l := log.WithField("func", "dispatchTask")
|
l := log.WithField("func", "dispatchTask")
|
||||||
defer func() {
|
defer func() {
|
||||||
val := p.metric.DecBusyWorker()
|
p.metric.DecBusyWorker()
|
||||||
e := recover()
|
e := recover()
|
||||||
if e != nil {
|
if e != nil {
|
||||||
l.Errorf("panic error: %v", e)
|
l.Errorf("panic error: %v", e)
|
||||||
}
|
}
|
||||||
p.schedule()
|
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)
|
runCtx, cancel := context.WithTimeout(ctx, time.Hour)
|
||||||
|
|
Loading…
Reference in New Issue