(ctx context.Context, dc *docker.Container)
| 289 | } |
| 290 | |
| 291 | func (c *Container) wait(ctx context.Context, dc *docker.Container) error { |
| 292 | c.log.Trace("in monitoring loop") |
| 293 | for { |
| 294 | select { |
| 295 | case exit := <-dc.ContainerWaiter.Waiter: |
| 296 | c.log.Tracef("container exited with %d", exit.StatusCode) |
| 297 | if exit.Error != nil { |
| 298 | return fmt.Errorf("receiving container exit: %s", exit.Error.Message) |
| 299 | } |
| 300 | return aproto.NewContainerExit(aproto.ExitCode(exit.StatusCode)) |
| 301 | |
| 302 | case err := <-dc.ContainerWaiter.Errs: |
| 303 | c.log.Trace("container waiter failed") |
| 304 | return fmt.Errorf("failed while waiting for container to exit: %w", err) |
| 305 | |
| 306 | case signal := <-c.signals: |
| 307 | c.log.Tracef("container signaled: %s", signal) |
| 308 | if err := c.cruntime.SignalContainer(ctx, dc.ContainerInfo.ID, signal); err != nil { |
| 309 | c.log.WithError(err).Errorf( |
| 310 | "failed to signal %v with %v", dc.ContainerInfo.ID, signal, |
| 311 | ) |
| 312 | return aproto.NewContainerFailure(aproto.ContainerFailed, err) |
| 313 | } |
| 314 | |
| 315 | case <-ctx.Done(): |
| 316 | c.log.Trace("container context canceled") |
| 317 | return ctx.Err() |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | func (c *Container) finalize(ctx context.Context, err error) { |
| 323 | c.log.Trace("finalizing container exit") |
no test coverage detected