Skip to content

Instantly share code, notes, and snippets.

@tejasmanohar
Last active February 3, 2017 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tejasmanohar/2cd8772ba898d0b9cf7ea93fbc0a34a6 to your computer and use it in GitHub Desktop.
Save tejasmanohar/2cd8772ba898d0b9cf7ea93fbc0a34a6 to your computer and use it in GitHub Desktop.
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