| OLD | NEW |
| 1 package task_scheduler | 1 package scheduling |
| 2 | 2 |
| 3 import ( | 3 import ( |
| 4 "fmt" | 4 "fmt" |
| 5 "math" | 5 "math" |
| 6 "path" | 6 "path" |
| 7 "sort" | 7 "sort" |
| 8 "sync" | 8 "sync" |
| 9 "time" | 9 "time" |
| 10 | 10 |
| 11 swarming_api "github.com/luci/luci-go/common/api/swarming/swarming/v1" | 11 swarming_api "github.com/luci/luci-go/common/api/swarming/swarming/v1" |
| 12 "github.com/skia-dev/glog" | 12 "github.com/skia-dev/glog" |
| 13 "go.skia.org/infra/build_scheduler/go/db" | |
| 14 "go.skia.org/infra/go/buildbot" | 13 "go.skia.org/infra/go/buildbot" |
| 15 "go.skia.org/infra/go/gitinfo" | 14 "go.skia.org/infra/go/gitinfo" |
| 16 "go.skia.org/infra/go/gitrepo" | 15 "go.skia.org/infra/go/gitrepo" |
| 17 "go.skia.org/infra/go/isolate" | 16 "go.skia.org/infra/go/isolate" |
| 18 "go.skia.org/infra/go/metrics2" | 17 "go.skia.org/infra/go/metrics2" |
| 19 "go.skia.org/infra/go/swarming" | 18 "go.skia.org/infra/go/swarming" |
| 20 "go.skia.org/infra/go/timer" | 19 "go.skia.org/infra/go/timer" |
| 21 "go.skia.org/infra/go/util" | 20 "go.skia.org/infra/go/util" |
| 21 "go.skia.org/infra/task_scheduler/go/db" |
| 22 ) | 22 ) |
| 23 | 23 |
| 24 // TaskScheduler is a struct used for scheduling tasks on bots. | 24 // TaskScheduler is a struct used for scheduling tasks on bots. |
| 25 type TaskScheduler struct { | 25 type TaskScheduler struct { |
| 26 cache db.TaskCache | 26 cache db.TaskCache |
| 27 db db.DB | 27 db db.DB |
| 28 isolate *isolate.Client | 28 isolate *isolate.Client |
| 29 period time.Duration | 29 period time.Duration |
| 30 queue []*taskCandidate | 30 queue []*taskCandidate |
| 31 queueMtx sync.RWMutex | 31 queueMtx sync.RWMutex |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 s.queueMtx.Lock() | 455 s.queueMtx.Lock() |
| 456 defer s.queueMtx.Unlock() | 456 defer s.queueMtx.Unlock() |
| 457 s.queue = rvCandidates | 457 s.queue = rvCandidates |
| 458 return nil | 458 return nil |
| 459 } | 459 } |
| 460 | 460 |
| 461 // getCandidatesToSchedule matches the list of free Swarming bots to task | 461 // getCandidatesToSchedule matches the list of free Swarming bots to task |
| 462 // candidates in the queue and returns the candidates which should be run. | 462 // candidates in the queue and returns the candidates which should be run. |
| 463 // Assumes that the tasks are sorted in decreasing order by score. | 463 // Assumes that the tasks are sorted in decreasing order by score. |
| 464 func getCandidatesToSchedule(bots []*swarming_api.SwarmingRpcsBotInfo, tasks []*
taskCandidate) []*taskCandidate { | 464 func getCandidatesToSchedule(bots []*swarming_api.SwarmingRpcsBotInfo, tasks []*
taskCandidate) []*taskCandidate { |
| 465 » defer timer.New("task_scheduler.getCandidatesToSchedule").Stop() | 465 » defer timer.New("scheduling.getCandidatesToSchedule").Stop() |
| 466 // Create a bots-by-swarming-dimension mapping. | 466 // Create a bots-by-swarming-dimension mapping. |
| 467 botsByDim := map[string]util.StringSet{} | 467 botsByDim := map[string]util.StringSet{} |
| 468 for _, b := range bots { | 468 for _, b := range bots { |
| 469 for _, dim := range b.Dimensions { | 469 for _, dim := range b.Dimensions { |
| 470 for _, val := range dim.Value { | 470 for _, val := range dim.Value { |
| 471 d := fmt.Sprintf("%s:%s", dim.Key, val) | 471 d := fmt.Sprintf("%s:%s", dim.Key, val) |
| 472 if _, ok := botsByDim[d]; !ok { | 472 if _, ok := botsByDim[d]; !ok { |
| 473 botsByDim[d] = util.StringSet{} | 473 botsByDim[d] = util.StringSet{} |
| 474 } | 474 } |
| 475 botsByDim[d][b.BotId] = true | 475 botsByDim[d][b.BotId] = true |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 }(i, t) | 867 }(i, t) |
| 868 } | 868 } |
| 869 wg.Wait() | 869 wg.Wait() |
| 870 for _, err := range errs { | 870 for _, err := range errs { |
| 871 if err != nil { | 871 if err != nil { |
| 872 return err | 872 return err |
| 873 } | 873 } |
| 874 } | 874 } |
| 875 return nil | 875 return nil |
| 876 } | 876 } |
| OLD | NEW |