github.com/justinjmoses/evergreen@v0.0.0-20170530173719-1d50e381ff0d/scheduler/task_finder.go (about) 1 package scheduler 2 3 import ( 4 "github.com/evergreen-ci/evergreen/model/task" 5 "github.com/mongodb/grip" 6 ) 7 8 // TaskFinder finds all tasks that are ready to be run. 9 type TaskFinder interface { 10 // Returns a slice of tasks that are ready to be run, and an error if 11 // appropriate. 12 FindRunnableTasks() ([]task.Task, error) 13 } 14 15 // DBTaskFinder fetches tasks from the database. Implements TaskFinder. 16 type DBTaskFinder struct{} 17 18 // FindRunnableTasks finds all tasks that are ready to be run. 19 // This works by fetching all undispatched tasks from the database, 20 // and filtering out any whose dependencies are not met. 21 func (self *DBTaskFinder) FindRunnableTasks() ([]task.Task, error) { 22 23 // find all of the undispatched tasks 24 undispatchedTasks, err := task.Find(task.IsUndispatched) 25 if err != nil { 26 return nil, err 27 } 28 29 // filter out any tasks whose dependencies are not met 30 runnableTasks := make([]task.Task, 0, len(undispatchedTasks)) 31 dependencyCaches := make(map[string]task.Task) 32 for _, task := range undispatchedTasks { 33 depsMet, err := task.DependenciesMet(dependencyCaches) 34 if err != nil { 35 grip.Errorf("Error checking dependencies for task %s: %+v", task.Id, err) 36 continue 37 } 38 if depsMet { 39 runnableTasks = append(runnableTasks, task) 40 } 41 } 42 43 return runnableTasks, nil 44 }