mirror of
https://github.com/docker/compose.git
synced 2026-06-28 12:13:24 +00:00
refactor(compose): collapse trivial event-helper wrappers in progress.go
Assisted-By: docker-agent Signed-off-by: Nicolas De loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
616adea1b1
commit
da530c7233
6 changed files with 23 additions and 73 deletions
|
|
@ -193,7 +193,7 @@ func (c *convergence) ensureService(ctx context.Context, project *types.Project,
|
|||
name := getContainerProgressName(ctr)
|
||||
switch ctr.State {
|
||||
case container.StateRunning:
|
||||
c.compose.events.On(runningEvent(name))
|
||||
c.compose.events.On(newEvent(name, api.Done, api.StatusRunning))
|
||||
case container.StateCreated:
|
||||
case container.StateRestarting:
|
||||
case container.StateExited:
|
||||
|
|
@ -927,7 +927,7 @@ func (s *composeService) startService(ctx context.Context,
|
|||
}
|
||||
|
||||
eventName := getContainerProgressName(ctr)
|
||||
s.events.On(startingEvent(eventName))
|
||||
s.events.On(newEvent(eventName, api.Working, api.StatusStarting))
|
||||
_, err = s.apiClient().ContainerStart(ctx, ctr.ID, client.ContainerStartOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -940,7 +940,7 @@ func (s *composeService) startService(ctx context.Context,
|
|||
}
|
||||
}
|
||||
|
||||
s.events.On(startedEvent(eventName))
|
||||
s.events.On(newEvent(eventName, api.Done, api.StatusStarted))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -299,7 +299,7 @@ func (s *composeService) removeVolume(ctx context.Context, id string) error {
|
|||
|
||||
func (s *composeService) stopContainer(ctx context.Context, service *types.ServiceConfig, ctr containerType.Summary, timeout *time.Duration, listener api.ContainerEventListener) error {
|
||||
eventName := getContainerProgressName(ctr)
|
||||
s.events.On(stoppingEvent(eventName))
|
||||
s.events.On(newEvent(eventName, api.Working, api.StatusStopping))
|
||||
|
||||
if service != nil {
|
||||
for _, hook := range service.PreStop {
|
||||
|
|
@ -321,7 +321,7 @@ func (s *composeService) stopContainer(ctx context.Context, service *types.Servi
|
|||
s.events.On(errorEvent(eventName, "Error while Stopping"))
|
||||
return err
|
||||
}
|
||||
s.events.On(stoppedEvent(eventName))
|
||||
s.events.On(newEvent(eventName, api.Done, api.StatusStopped))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ func (s *composeService) kill(ctx context.Context, projectName string, options a
|
|||
containers.forEach(func(ctr container.Summary) {
|
||||
eg.Go(func() error {
|
||||
eventName := getContainerProgressName(ctr)
|
||||
s.events.On(killingEvent(eventName))
|
||||
s.events.On(newEvent(eventName, api.Working, api.StatusKilling))
|
||||
_, err := s.apiClient().ContainerKill(ctx, ctr.ID, client.ContainerKillOptions{
|
||||
Signal: options.Signal,
|
||||
})
|
||||
|
|
@ -69,7 +69,7 @@ func (s *composeService) kill(ctx context.Context, projectName string, options a
|
|||
s.events.On(errorEvent(eventName, "Error while Killing"))
|
||||
return err
|
||||
}
|
||||
s.events.On(killedEvent(eventName))
|
||||
s.events.On(newEvent(eventName, api.Done, api.StatusKilled))
|
||||
return nil
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -52,66 +52,11 @@ func creatingEvent(id string) api.Resource {
|
|||
return newEvent(id, api.Working, api.StatusCreating)
|
||||
}
|
||||
|
||||
// startingEvent creates a new Starting in progress Resource
|
||||
func startingEvent(id string) api.Resource {
|
||||
return newEvent(id, api.Working, api.StatusStarting)
|
||||
}
|
||||
|
||||
// startedEvent creates a new Started in progress Resource
|
||||
func startedEvent(id string) api.Resource {
|
||||
return newEvent(id, api.Done, api.StatusStarted)
|
||||
}
|
||||
|
||||
// waiting creates a new waiting event
|
||||
func waiting(id string) api.Resource {
|
||||
return newEvent(id, api.Working, api.StatusWaiting)
|
||||
}
|
||||
|
||||
// healthy creates a new healthy event
|
||||
func healthy(id string) api.Resource {
|
||||
return newEvent(id, api.Done, api.StatusHealthy)
|
||||
}
|
||||
|
||||
// exited creates a new exited event
|
||||
func exited(id string) api.Resource {
|
||||
return newEvent(id, api.Done, api.StatusExited)
|
||||
}
|
||||
|
||||
// restartingEvent creates a new Restarting in progress Resource
|
||||
func restartingEvent(id string) api.Resource {
|
||||
return newEvent(id, api.Working, api.StatusRestarting)
|
||||
}
|
||||
|
||||
// runningEvent creates a new Running in progress Resource
|
||||
func runningEvent(id string) api.Resource {
|
||||
return newEvent(id, api.Done, api.StatusRunning)
|
||||
}
|
||||
|
||||
// createdEvent creates a new Created (done) Resource
|
||||
func createdEvent(id string) api.Resource {
|
||||
return newEvent(id, api.Done, api.StatusCreated)
|
||||
}
|
||||
|
||||
// stoppingEvent creates a new Stopping in progress Resource
|
||||
func stoppingEvent(id string) api.Resource {
|
||||
return newEvent(id, api.Working, api.StatusStopping)
|
||||
}
|
||||
|
||||
// stoppedEvent creates a new Stopping in progress Resource
|
||||
func stoppedEvent(id string) api.Resource {
|
||||
return newEvent(id, api.Done, api.StatusStopped)
|
||||
}
|
||||
|
||||
// killingEvent creates a new Killing in progress Resource
|
||||
func killingEvent(id string) api.Resource {
|
||||
return newEvent(id, api.Working, api.StatusKilling)
|
||||
}
|
||||
|
||||
// killedEvent creates a new Killed in progress Resource
|
||||
func killedEvent(id string) api.Resource {
|
||||
return newEvent(id, api.Done, api.StatusKilled)
|
||||
}
|
||||
|
||||
// removingEvent creates a new Removing in progress Resource
|
||||
func removingEvent(id string) api.Resource {
|
||||
return newEvent(id, api.Working, api.StatusRemoving)
|
||||
|
|
@ -132,17 +77,22 @@ func builtEvent(id string) api.Resource {
|
|||
return newEvent("Image "+id, api.Done, api.StatusBuilt)
|
||||
}
|
||||
|
||||
// pullingEvent creates a new pulling (in progress) Resource
|
||||
func pullingEvent(id string) api.Resource {
|
||||
return newEvent("Image "+id, api.Working, api.StatusPulling)
|
||||
// waiting creates a new waiting event; kept as a named func for use as a function value.
|
||||
func waiting(id string) api.Resource {
|
||||
return newEvent(id, api.Working, api.StatusWaiting)
|
||||
}
|
||||
|
||||
// pulledEvent creates a new pulled (done) Resource
|
||||
func pulledEvent(id string) api.Resource {
|
||||
return newEvent("Image "+id, api.Done, api.StatusPulled)
|
||||
// healthy creates a new healthy event; kept as a named func for use as a function value.
|
||||
func healthy(id string) api.Resource {
|
||||
return newEvent(id, api.Done, api.StatusHealthy)
|
||||
}
|
||||
|
||||
// skippedEvent creates a new Skipped Resource
|
||||
// exited creates a new exited event; kept as a named func for use as a function value.
|
||||
func exited(id string) api.Resource {
|
||||
return newEvent(id, api.Done, api.StatusExited)
|
||||
}
|
||||
|
||||
// skippedEvent creates a new Skipped Resource; kept as a named func for use as a function value.
|
||||
func skippedEvent(id string, reason string) api.Resource {
|
||||
return api.Resource{
|
||||
ID: id,
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ func getUnwrappedErrorMessage(err error) string {
|
|||
|
||||
func (s *composeService) pullServiceImage(ctx context.Context, service types.ServiceConfig, quietPull bool, defaultPlatform string) (string, error) {
|
||||
resource := "Image " + service.Image
|
||||
s.events.On(pullingEvent(service.Image))
|
||||
s.events.On(newEvent("Image "+service.Image, api.Working, api.StatusPulling))
|
||||
ref, err := reference.ParseNormalizedNamed(service.Image)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
@ -246,7 +246,7 @@ func (s *composeService) pullServiceImage(ctx context.Context, service types.Ser
|
|||
toPullProgressEvent(resource, jm, s.events)
|
||||
}
|
||||
}
|
||||
s.events.On(pulledEvent(service.Image))
|
||||
s.events.On(newEvent("Image "+service.Image, api.Done, api.StatusPulled))
|
||||
|
||||
inspected, err := s.apiClient().ImageInspect(ctx, service.Image)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -93,14 +93,14 @@ func (s *composeService) restart(ctx context.Context, projectName string, option
|
|||
}
|
||||
}
|
||||
eventName := getContainerProgressName(ctr)
|
||||
s.events.On(restartingEvent(eventName))
|
||||
s.events.On(newEvent(eventName, api.Working, api.StatusRestarting))
|
||||
_, err = s.apiClient().ContainerRestart(ctx, ctr.ID, client.ContainerRestartOptions{
|
||||
Timeout: utils.DurationSecondToInt(options.Timeout),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.events.On(startedEvent(eventName))
|
||||
s.events.On(newEvent(eventName, api.Done, api.StatusStarted))
|
||||
for _, hook := range def.PostStart {
|
||||
err = s.runHook(ctx, ctr, def, hook, nil)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue