Skip to content

Commit

Permalink
Merge pull request #73 from buildkite/defer-close-on-tickers
Browse files Browse the repository at this point in the history
Defer call to stop ticker when spot listener returns
  • Loading branch information
lox authored Feb 25, 2019
2 parents 352ecac + 85752ab commit 8513ff8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions spot.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ func (l *SpotListener) Start(ctx context.Context, notices chan<- TerminationNoti
if !l.metadata.Available() {
return errors.New("ec2 metadata is not available")
}

tockChan := time.NewTicker(l.interval).C


ticker := time.NewTicker(l.interval)
defer ticker.Stop()

for {
select {
case <-ctx.Done():
return nil
case <-tockChan:
case <-ticker.C:
log.Debug("Polling ec2 metadata for spot termination notices")

out, err := l.metadata.GetMetadata("spot/termination-time")
Expand Down

0 comments on commit 8513ff8

Please sign in to comment.