Skip to content

Commit

Permalink
DESS-1710: modified WaitForBuildToFinish function (#4270)
Browse files Browse the repository at this point in the history
* DESS-1710: modified WaitForBuildToFinish function - added exception handling

* DESS-1710: fixed parameters in WaitForBuildToFinish

* DESS-1710: added error handling in WaitForBuildToFinish

* DESS-1710: formatted build.go

* DESS-1710: fixed error logging

* DESS-1710: fixed Poll retrying

* DESS-1710: renamed WaitForBuildToFinish

* DESS-1710: refactored WaitForBuildToFinish

* DESS-1710: changed maxRetries to 4 attempt

* DESS-1710: fixed error handling

---------

Co-authored-by: Christopher Fenner <[email protected]>
Co-authored-by: Ashly Mathew <[email protected]>
  • Loading branch information
3 people authored May 2, 2023
1 parent 6dad124 commit fbb27b2
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions pkg/jenkins/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,38 @@ type Build interface {
}

// WaitForBuildToFinish waits till a build is finished.
func WaitForBuildToFinish(ctx context.Context, build Build, pollInterval time.Duration) {
func WaitForBuildToFinish(ctx context.Context, build Build, pollInterval time.Duration) error {
//TODO: handle timeout?
maxRetries := 4

for build.IsRunning(ctx) {
time.Sleep(pollInterval)
build.Poll(ctx)
//TODO: add 404/503 response code handling
_, err := build.Poll(ctx)

if err == nil {
continue
}

fmt.Printf("Error occurred while waiting for build to finish: %v. Retrying...\n", err)

for i := 0; i < maxRetries; i++ {
time.Sleep(pollInterval)
_, err = build.Poll(ctx)

if err == nil {
break
}

fmt.Printf("Error occurred while waiting for build to finish: %v. Retrying...\n", err)
}

if err != nil {
return fmt.Errorf("Max retries (%v) exceeded while waiting for build to finish. Last error: %w", maxRetries, err)
}
}

return nil
}

// FetchBuildArtifact is fetching a build artifact from a finished build with a certain name.
Expand Down

0 comments on commit fbb27b2

Please sign in to comment.