github.com/justinjmoses/evergreen@v0.0.0-20170530173719-1d50e381ff0d/scheduler/setup_funcs.go (about)

     1  package scheduler
     2  
     3  import (
     4  	"github.com/evergreen-ci/evergreen"
     5  	"github.com/evergreen-ci/evergreen/model/task"
     6  	"github.com/pkg/errors"
     7  )
     8  
     9  // Function run before sorting all the tasks.  Used to fetch and store
    10  // information needed for prioritizing the tasks.
    11  type sortSetupFunc func(comparator *CmpBasedTaskComparator) error
    12  
    13  // Get all of the previous completed tasks for the ones to be sorted, and cache
    14  // them appropriately.
    15  func cachePreviousTasks(comparator *CmpBasedTaskComparator) (err error) {
    16  	// get the relevant previous completed tasks
    17  	comparator.previousTasksCache = make(map[string]task.Task)
    18  	for _, t := range comparator.tasks {
    19  		prevTask := &task.Task{}
    20  
    21  		// only relevant for repotracker tasks
    22  		if t.Requester == evergreen.RepotrackerVersionRequester {
    23  			prevTask, err = t.PreviousCompletedTask(t.Project, []string{})
    24  			if err != nil {
    25  				return errors.Wrap(err, "cachePreviousTasks")
    26  			}
    27  			if prevTask == nil {
    28  				prevTask = &task.Task{}
    29  			}
    30  		}
    31  		comparator.previousTasksCache[t.Id] = *prevTask
    32  	}
    33  
    34  	return nil
    35  }
    36  
    37  // cacheSimilarFailing fetches all failed tasks with the same display name,
    38  // revision, requester and project but in other buildvariants
    39  func cacheSimilarFailing(comparator *CmpBasedTaskComparator) (err error) {
    40  	// find if there are any similar failing tasks
    41  	comparator.similarFailingCount = make(map[string]int)
    42  	for _, task := range comparator.tasks {
    43  		numSimilarFailing := 0
    44  
    45  		// only relevant for repotracker tasks
    46  		if task.Requester == evergreen.RepotrackerVersionRequester {
    47  			numSimilarFailing, err = task.CountSimilarFailingTasks()
    48  			if err != nil {
    49  				return errors.Wrap(err, "cacheSimilarFailing")
    50  			}
    51  		}
    52  		comparator.similarFailingCount[task.Id] = numSimilarFailing
    53  	}
    54  	return nil
    55  }