Skip to content

Commit

Permalink
Merge pull request #971 from convox/wait-for-template
Browse files Browse the repository at this point in the history
wait for template to be available on s3 bucket before proceeding
  • Loading branch information
ddollar authored Aug 2, 2016
2 parents 9257939 + afaf275 commit 2f0ee30
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions api/models/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ func (r *Release) Promote() error {
return err
}

// loop until we can find the template
if err := waitForTemplate(app.Outputs["Settings"], r.Id); err != nil {
return fmt.Errorf("error waiting for template: %s", err)
}

url := fmt.Sprintf("https://s3.amazonaws.com/%s/templates/%s", app.Outputs["Settings"], r.Id)

req := &cloudformation.UpdateStackInput{
Expand Down Expand Up @@ -567,3 +572,26 @@ func releaseFromItem(item map[string]*dynamodb.AttributeValue) *Release {

return release
}

func waitForTemplate(bucket string, id string) error {
tick := time.Tick(1 * time.Second)
timeout := time.Tick(1 * time.Minute)

for {
select {
case <-tick:
fmt.Printf("ns=kernel at=waitForTemplate.tick bucket=%q release=%q\n", bucket, id)
_, err := s3Get(bucket, fmt.Sprintf("templates/%s", id))
if err == nil {
fmt.Printf("ns=kernel at=waitForTemplate.tick status=found bucket=%q release=%q\n", bucket, id)
return nil
}
case <-timeout:
fmt.Printf("ns=kernel at=waitForTemplate.tick error=timeout bucket=%q release=%q\n", bucket, id)
return fmt.Errorf("timeout")
}
}

fmt.Printf("ns=kernel at=waitForTemplate.tick error=unknown bucket=%q release=%q\n", bucket, id)
return fmt.Errorf("unknown error")
}

0 comments on commit 2f0ee30

Please sign in to comment.