Skip to content

Commit

Permalink
Defer call to stop ticker when spot listener returns
Browse files Browse the repository at this point in the history
  • Loading branch information
itsdalmo committed Feb 25, 2019
1 parent 352ecac commit 85752ab
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 85752ab

Please sign in to comment.