Last active
February 3, 2017 08:13
-
-
Save tejasmanohar/2cd8772ba898d0b9cf7ea93fbc0a34a6 to your computer and use it in GitHub Desktop.
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
type Monitor struct { | |
tasks map[string]*task | |
} | |
type task struct { | |
*ecs.Task | |
status schedulerStatus | |
} | |
func New() *Monitor { | |
m := Monitor{tasks: map[string]task{}} | |
go m.run() | |
return &m | |
} | |
func (m *Monitor) run() { | |
for range time.Tick(frequency) { | |
m.tick() | |
} | |
} | |
func (m *Monitor) tick() error { | |
var taskIDs []string | |
for taskID := range m.tasks { | |
taskIDs = append(taskIDs, taskID) | |
} | |
resp := aws.DescribeTasks(taskIDs) | |
for _, task := range resp.Tasks { | |
if task.Done { | |
m.tasks[task.ID] = getStatus(task.Containers[0]) | |
} | |
} | |
} | |
func (m *Monitor) Watch(ecsTask *ecs.Task) { | |
m.tasks[ecsTask.ID] = task{Task: ecsTask} | |
} | |
func (m *Monitor) GetStatus() map[string]*status { | |
return m.tasks | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment