Revert "fix(docker redis): Fix redis docker randomly panic. (#267)"

This reverts commit c8c063b622.
This commit is contained in:
Péter Garamvölgyi
2023-01-31 11:04:51 +01:00
parent 289bfb0a91
commit 65bd19859f
2 changed files with 28 additions and 30 deletions

View File

@@ -42,35 +42,8 @@ func (r *ImgRedis) Start() error {
if id != "" {
return fmt.Errorf("container already exist, name: %s", r.name)
}
// Add check status function.
keyword := "Ready to accept connections"
okCh := make(chan struct{}, 1)
r.cmd.RegistFunc(keyword, func(buf string) {
if strings.Contains(buf, keyword) {
select {
case okCh <- struct{}{}:
default:
return
}
}
})
defer r.cmd.UnRegistFunc(keyword)
// Start redis.
r.cmd.RunCmd(true)
// Wait result of keyword.
select {
case <-okCh:
utils.TryTimes(3, func() bool {
r.id = GetContainerID(r.name)
return r.id != ""
})
case <-time.After(time.Second * 10):
}
// Set redis status.
r.running = r.id != ""
r.running = r.isOk()
if !r.running {
_ = r.Stop()
return fmt.Errorf("failed to start image: %s", r.image)
@@ -118,3 +91,30 @@ func (r *ImgRedis) prepare() []string {
}
return append(append(cmds, ports...), r.image)
}
func (r *ImgRedis) isOk() bool {
keyword := "Ready to accept connections"
okCh := make(chan struct{}, 1)
r.cmd.RegistFunc(keyword, func(buf string) {
if strings.Contains(buf, keyword) {
select {
case okCh <- struct{}{}:
default:
return
}
}
})
defer r.cmd.UnRegistFunc(keyword)
// Wait result.
select {
case <-okCh:
utils.TryTimes(3, func() bool {
r.id = GetContainerID(r.name)
return r.id != ""
})
return r.id != ""
case <-time.After(time.Second * 10):
return false
}
}

View File

@@ -33,8 +33,6 @@ func GetContainerID(name string) string {
filter := filters.NewArgs()
filter.Add("name", name)
lst, _ := cli.ContainerList(context.Background(), types.ContainerListOptions{
Latest: true,
Limit: 1,
Filters: filter,
})
if len(lst) > 0 {