Skip to content

Commit

Permalink
Use better algorithm for polling assembly status
Browse files Browse the repository at this point in the history
  • Loading branch information
Acconut committed Nov 19, 2018
1 parent 16fe138 commit e3d1daa
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@ import (
"time"
)

// WaitForAssembly fetches continuously the assembly status until is either
// completed (ASSEMBLY_COMPLETED), canceled (ASSEMBLY_CANCELED) or aborted
// (REQUEST_ABORTED). If you want to end this loop prematurely, you can cancel
// the supplied context.
// WaitForAssembly fetches continuously the assembly status until it has
// finished uploading and executing or until an assembly error occurs.
// If you want to end this loop prematurely, you can cancel the supplied context.
func (client *Client) WaitForAssembly(ctx context.Context, assembly *AssemblyInfo) (*AssemblyInfo, error) {
for {
res, err := client.GetAssembly(ctx, assembly.AssemblySSLURL)
if err != nil {
return nil, err
}

if res.Ok == "ASSEMBLY_COMPLETED" || res.Ok == "ASSEMBLY_CANCELED" || res.Ok == "REQUEST_ABORTED" {
// Abort polling if the assembly has entered an error state
if res.Error != "" {
return res, nil
}

// The polling is done if the assembly is not uploading or executing anymore.
if res.Ok != "ASSEMBLY_UPLOADING" && res.Ok != "ASSEMBLY_EXECUTING" {
return res, nil
}

Expand Down

0 comments on commit e3d1daa

Please sign in to comment.