mirror of https://code.forgejo.org/forgejo/runner
chore(runner): update runner status if start program
parent
45b0429b21
commit
d4c1515f4e
|
@ -8,7 +8,7 @@ create a new file as name `.env`
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
GITEA_RUNNER_NAME=foobar
|
GITEA_RUNNER_NAME=foobar
|
||||||
GITEA_RUNNER_URL=localhost:3001/foo/bar
|
GITEA_RUNNER_URL=http://localhost:3000/foo/bar
|
||||||
GITEA_RUNNER_TOKEN=1234567890abcde
|
GITEA_RUNNER_TOKEN=1234567890abcde
|
||||||
GITEA_RUNNER_LABELS=foo,bar
|
GITEA_RUNNER_LABELS=foo,bar
|
||||||
```
|
```
|
||||||
|
|
|
@ -30,6 +30,7 @@ func New(endpoint, secret string, opts ...Option) *HTTPClient {
|
||||||
return next(ctx, req)
|
return next(ctx, req)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
cfg.opts = append(cfg.opts, connect.WithInterceptors(interceptor))
|
cfg.opts = append(cfg.opts, connect.WithInterceptors(interceptor))
|
||||||
|
|
||||||
if cfg.httpClient == nil {
|
if cfg.httpClient == nil {
|
||||||
|
|
|
@ -9,8 +9,9 @@ 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"
|
||||||
|
|
||||||
pingv1 "gitea.com/gitea/proto-go/ping/v1"
|
pingv1 "gitea.com/gitea/proto-go/ping/v1"
|
||||||
|
runnerv1 "gitea.com/gitea/proto-go/runner/v1"
|
||||||
|
|
||||||
"github.com/bufbuild/connect-go"
|
"github.com/bufbuild/connect-go"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
@ -98,9 +99,32 @@ func runDaemon(ctx context.Context, task *runtime.Task) func(cmd *cobra.Command,
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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_OFFLINE,
|
||||||
|
}),
|
||||||
|
); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return poller.Poll(ctx, cfg.Runner.Capacity)
|
return poller.Poll(ctx, cfg.Runner.Capacity)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
g.Go(func() error {
|
||||||
|
<-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()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).
|
log.WithError(err).
|
||||||
|
|
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-20221007122649-939e445f4abb
|
gitea.com/gitea/proto-go v0.0.0-20221013073523-69d53451957a
|
||||||
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
|
||||||
|
|
6
go.sum
6
go.sum
|
@ -25,10 +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-20220922135643-52a5bba9e7fa h1:HHqlvfIvqFlny3sgJgAM1BYeLNr1uM4yXtvF7aAoYK8=
|
gitea.com/gitea/act v0.0.0-20220922135643-52a5bba9e7fa h1:HHqlvfIvqFlny3sgJgAM1BYeLNr1uM4yXtvF7aAoYK8=
|
||||||
gitea.com/gitea/act v0.0.0-20220922135643-52a5bba9e7fa/go.mod h1:9W/Nz16tjfnWp7O5DUo3EjZBnZFBI/5rlWstX4o7+hU=
|
gitea.com/gitea/act v0.0.0-20220922135643-52a5bba9e7fa/go.mod h1:9W/Nz16tjfnWp7O5DUo3EjZBnZFBI/5rlWstX4o7+hU=
|
||||||
gitea.com/gitea/proto-go v0.0.0-20221002020351-750a3b99a850 h1:BDnr9A52zCPb5BH64yTm8cIfhhjTvql0u6QvWjJViGo=
|
gitea.com/gitea/proto-go v0.0.0-20221013073523-69d53451957a h1:WHNPcbDR2vw2a17Ml06+n4MC0UwsyD/F3WeVteaXWMI=
|
||||||
gitea.com/gitea/proto-go v0.0.0-20221002020351-750a3b99a850/go.mod h1:hD8YwSHusjwjEEgubW6XFvnZuNhMZTHz6lwjfltEt/Y=
|
gitea.com/gitea/proto-go v0.0.0-20221013073523-69d53451957a/go.mod h1:hD8YwSHusjwjEEgubW6XFvnZuNhMZTHz6lwjfltEt/Y=
|
||||||
gitea.com/gitea/proto-go v0.0.0-20221007122649-939e445f4abb h1:Wi8BEd1hStpvZW0PUP6W74mQRMJOJ/EhPoqWW5dcHQc=
|
|
||||||
gitea.com/gitea/proto-go v0.0.0-20221007122649-939e445f4abb/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=
|
||||||
|
|
|
@ -126,10 +126,7 @@ func (p *Poller) poll(ctx context.Context, thread int) error {
|
||||||
|
|
||||||
// request a new build stage for execution from the central
|
// request a new build stage for execution from the central
|
||||||
// build server.
|
// build server.
|
||||||
resp, err := p.Client.FetchTask(ctx, connect.NewRequest(&runnerv1.FetchTaskRequest{
|
resp, err := p.Client.FetchTask(ctx, connect.NewRequest(&runnerv1.FetchTaskRequest{}))
|
||||||
Os: p.Filter.OS,
|
|
||||||
Arch: p.Filter.Arch,
|
|
||||||
}))
|
|
||||||
if err == context.Canceled || err == context.DeadlineExceeded {
|
if err == context.Canceled || err == context.DeadlineExceeded {
|
||||||
l.WithError(err).Trace("poller: no stage returned")
|
l.WithError(err).Trace("poller: no stage returned")
|
||||||
p.errorRetryCounter++
|
p.errorRetryCounter++
|
||||||
|
|
Loading…
Reference in New Issue