Implement Container Readiness Check in Manager
- Added a loop in the ensureRunning method to wait for the Docker container to be in a running state before proceeding, enhancing reliability in container management. - Included error handling for container inspection to ensure proper feedback in case of failures during the readiness check.
This commit is contained in:
parent
55e43a7edd
commit
08e7ed36a3
1 changed files with 12 additions and 0 deletions
|
|
@ -231,6 +231,18 @@ func (m *Manager) ensureRunning(ctx context.Context, name string) error {
|
||||||
return fmt.Errorf("failed to start container: %w", err)
|
return fmt.Errorf("failed to start container: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait for container to be ready (inspect until running)
|
||||||
|
for i := 0; i < 30; i++ {
|
||||||
|
info, err := m.dockerClient.ContainerInspect(ctx, cont.ID)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to inspect container: %w", err)
|
||||||
|
}
|
||||||
|
if info.State.Running {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
cont.Status = StatusRunning
|
cont.Status = StatusRunning
|
||||||
cont.LastUsedAt = time.Now()
|
cont.LastUsedAt = time.Now()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue