forked from LeanerCloud/AutoSpotting
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge processAllRegions into main.go
- Loading branch information
Showing
2 changed files
with
26 additions
and
59 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
||
} |