github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/model/expected_task_durations.go (about) 1 package model 2 3 import ( 4 "time" 5 6 "github.com/evergreen-ci/evergreen/model/task" 7 ) 8 9 const ( 10 // if we have no data on a given task, default to 10 minutes so we 11 // have some new hosts spawned 12 DefaultTaskDuration = time.Duration(10) * time.Minute 13 14 // for the UI, if we have no data on a given task, we want to default to 15 // 0 time 16 UnknownTaskDuration = time.Duration(0) 17 18 // indicates the window of completed tasks we want to use in computing 19 // average task duration. By default we use tasks that have 20 // completed within the last 7 days 21 TaskCompletionEstimateWindow = time.Duration(24*7) * time.Hour 22 ) 23 24 // ProjectTaskDurations maintans a mapping of a given project's name 25 // and its accompanying BuildVariantTaskDurations 26 type ProjectTaskDurations struct { 27 TaskDurationByProject map[string]*BuildVariantTaskDurations 28 } 29 30 // BuildVariantTaskDurations maintains a mapping between a buildvariant 31 // and its accompanying TaskDurations 32 type BuildVariantTaskDurations struct { 33 TaskDurationByBuildVariant map[string]*TaskDurations 34 } 35 36 // TaskDurations maintains a mapping between a given task (by display name) 37 // and its accompanying aggregate expected duration 38 type TaskDurations struct { 39 TaskDurationByDisplayName map[string]time.Duration 40 } 41 42 // GetTaskExpectedDuration returns the expected duration for a given task 43 // if the task does not exist, it returns model.DefaultTaskDuration 44 func GetTaskExpectedDuration(task task.Task, 45 allDurations ProjectTaskDurations) time.Duration { 46 projectDur, ok := allDurations.TaskDurationByProject[task.Project] 47 if ok { 48 buildVariantDur := projectDur.TaskDurationByBuildVariant 49 projectDur, ok := buildVariantDur[task.BuildVariant] 50 if ok { 51 taskDur := projectDur.TaskDurationByDisplayName 52 duration, ok := taskDur[task.DisplayName] 53 if ok { 54 return duration 55 } 56 } 57 } 58 return DefaultTaskDuration 59 }