Skip to content

Commit

Permalink
Merge processAllRegions into main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
cristim committed Oct 4, 2016
1 parent a1209bc commit b7f409f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 59 deletions.
54 changes: 0 additions & 54 deletions core/instance_replacement.go

This file was deleted.

31 changes: 26 additions & 5 deletions core/main.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
package autospotting

import "sync"

// Run starts processing all AWS regions looking for AutoScaling groups
// enabled and taking action by replacing more pricy on-demand instances with
// compatible and cheaper spot instances.
func Run(instancesFile string) {

initLogger()

var ir instanceReplacement

// TODO: we could cache this data locally for a while, like for a few days
var jsonInst jsonInstances

logger.Println("Loading on-demand instance pricing information")
jsonInst.loadFromFile(instancesFile)

// logger.Println(spew.Sdump(jsonInst))
processAllRegions(&jsonInst)

}

ir.processAllRegions(&jsonInst)
func processAllRegions(instData *jsonInstances) {
// for each region in parallel
// for each of the ASGs tagged with 'spot-enabled=true'

var wg sync.WaitGroup

regions, err := getRegions()

if err != nil {
logger.Println(err.Error())
return
}
for _, r := range regions {
wg.Add(1)
r := region{name: r}
go func() {
r.processRegion(instData)
wg.Done()
}()
}
wg.Wait()

}

0 comments on commit b7f409f

Please sign in to comment.