fixup! refactor(container): restart handling
This commit is contained in:
parent
f776a2fe16
commit
e39ac23f69
@ -377,12 +377,7 @@ func (a *Client) runContainerLoop(
|
|||||||
respC, errC := a.apiClient.ContainerWait(ctx, containerID, container.WaitConditionNextExit)
|
respC, errC := a.apiClient.ContainerWait(ctx, containerID, container.WaitConditionNextExit)
|
||||||
select {
|
select {
|
||||||
case resp := <-respC:
|
case resp := <-respC:
|
||||||
if shouldRestartFunc != nil {
|
exit := func(err error) {
|
||||||
shouldRestart, err := shouldRestartFunc(resp.StatusCode, restartCount, time.Since(startedWaitingAt))
|
|
||||||
if shouldRestart && err != nil {
|
|
||||||
panic(fmt.Errorf("shouldRestart must return nil error if restarting, but returned: %w", err))
|
|
||||||
}
|
|
||||||
if !shouldRestart {
|
|
||||||
a.logger.Info("Container exited", "id", shortID(containerID), "should_restart", "false", "exit_code", resp.StatusCode, "restart_count", restartCount)
|
a.logger.Info("Container exited", "id", shortID(containerID), "should_restart", "false", "exit_code", resp.StatusCode, "restart_count", restartCount)
|
||||||
containerRespC <- containerWaitResponse{
|
containerRespC <- containerWaitResponse{
|
||||||
WaitResponse: resp,
|
WaitResponse: resp,
|
||||||
@ -390,8 +385,20 @@ func (a *Client) runContainerLoop(
|
|||||||
restartCount: restartCount,
|
restartCount: restartCount,
|
||||||
err: err,
|
err: err,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if shouldRestartFunc == nil {
|
||||||
|
exit(nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shouldRestart, err := shouldRestartFunc(resp.StatusCode, restartCount, time.Since(startedWaitingAt))
|
||||||
|
if shouldRestart && err != nil {
|
||||||
|
panic(fmt.Errorf("shouldRestart must return nil error if restarting, but returned: %w", err))
|
||||||
|
}
|
||||||
|
if !shouldRestart {
|
||||||
|
exit(err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
a.logger.Info("Container exited", "id", shortID(containerID), "should_restart", "true", "exit_code", resp.StatusCode, "restart_count", restartCount)
|
a.logger.Info("Container exited", "id", shortID(containerID), "should_restart", "true", "exit_code", resp.StatusCode, "restart_count", restartCount)
|
||||||
|
@ -94,9 +94,6 @@ func TestClientRunContainer(t *testing.T) {
|
|||||||
Mode: 0755,
|
Mode: 0755,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ShouldRestart: func(int64, int, time.Duration) (bool, error) {
|
|
||||||
return false, nil
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user