Skip to content

Commit

Permalink
chore: move inside reuseReaper
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelapenya committed Jun 10, 2024
1 parent b835925 commit d7f1b71
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions reaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,26 +173,6 @@ func reuseOrCreateReaper(ctx context.Context, sessionID string, provider ReaperP
return nil, err
}

Logger.Printf("⏳ Waiting for Reaper port to be ready")

var containerJson *types.ContainerJSON

if containerJson, err = reaperContainer.Inspect(ctx); err != nil {
return nil, fmt.Errorf("failed to inspect reaper container %s: %w", reaperContainer.ID[:8], err)
}

if containerJson != nil && containerJson.NetworkSettings != nil {
for port := range containerJson.NetworkSettings.Ports {
err := wait.ForListeningPort(port).
WithPollInterval(100*time.Millisecond).
WaitUntilReady(ctx, reaperContainer)
if err != nil {
return nil, fmt.Errorf("failed waiting for reaper container %s port %s/%s to be ready: %w",
reaperContainer.ID[:8], port.Proto(), port.Port(), err)
}
}
}

return reaperInstance, nil
}

Expand Down Expand Up @@ -223,6 +203,27 @@ func reuseReaperContainer(ctx context.Context, sessionID string, provider Reaper
if err != nil {
return nil, err
}

Logger.Printf("⏳ Waiting for Reaper port to be ready")

var containerJson *types.ContainerJSON

if containerJson, err = reaperContainer.Inspect(ctx); err != nil {
return nil, fmt.Errorf("failed to inspect reaper container %s: %w", reaperContainer.ID[:8], err)
}

if containerJson != nil && containerJson.NetworkSettings != nil {
for port := range containerJson.NetworkSettings.Ports {
err := wait.ForListeningPort(port).
WithPollInterval(100*time.Millisecond).
WaitUntilReady(ctx, reaperContainer)
if err != nil {
return nil, fmt.Errorf("failed waiting for reaper container %s port %s/%s to be ready: %w",
reaperContainer.ID[:8], port.Proto(), port.Port(), err)
}
}
}

return &Reaper{
Provider: provider,
SessionID: sessionID,
Expand Down

0 comments on commit d7f1b71

Please sign in to comment.