mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-09-15 18:57:01 +00:00
fix: add service container health check
Refs: https://github.com/nektos/act/pull/2354/files Signed-off-by: https://github.com/ChristopherHX
This commit is contained in:
parent
8819e2a195
commit
d14092ea56
7 changed files with 94 additions and 2 deletions
|
@ -610,6 +610,7 @@ func (rc *RunContext) startJobContainer() common.Executor {
|
|||
Mode: 0o666,
|
||||
Body: "",
|
||||
}),
|
||||
rc.waitForServiceContainers(),
|
||||
)(ctx)
|
||||
}
|
||||
}
|
||||
|
@ -744,6 +745,40 @@ func (rc *RunContext) startServiceContainers(_ string) common.Executor {
|
|||
}
|
||||
}
|
||||
|
||||
func (rc *RunContext) waitForServiceContainer(c container.ExecutionsEnvironment) common.Executor {
|
||||
return func(ctx context.Context) error {
|
||||
sctx, cancel := context.WithTimeout(ctx, time.Minute*5)
|
||||
defer cancel()
|
||||
var health container.Health
|
||||
delay := time.Second
|
||||
for i := 0; ; i++ {
|
||||
health = c.GetHealth(sctx)
|
||||
if health != container.HealthStarting || i > 30 {
|
||||
break
|
||||
}
|
||||
time.Sleep(delay)
|
||||
delay *= 2
|
||||
if delay > 10*time.Second {
|
||||
delay = 10 * time.Second
|
||||
}
|
||||
}
|
||||
if health == container.HealthHealthy {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("service container failed to start")
|
||||
}
|
||||
}
|
||||
|
||||
func (rc *RunContext) waitForServiceContainers() common.Executor {
|
||||
return func(ctx context.Context) error {
|
||||
execs := []common.Executor{}
|
||||
for _, c := range rc.ServiceContainers {
|
||||
execs = append(execs, rc.waitForServiceContainer(c))
|
||||
}
|
||||
return common.NewParallelExecutor(len(execs), execs...)(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
func (rc *RunContext) stopServiceContainers() common.Executor {
|
||||
return func(ctx context.Context) error {
|
||||
execs := []common.Executor{}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue