| Index: ct/go/util/util.go
|
| diff --git a/ct/go/util/util.go b/ct/go/util/util.go
|
| index e69499571e5931fd2e1900fa47f49b38c967c093..4fe5e885e89d7e9bc204289066f7cb69cd1d0944 100644
|
| --- a/ct/go/util/util.go
|
| +++ b/ct/go/util/util.go
|
| @@ -16,6 +16,7 @@ import (
|
| "time"
|
|
|
| "go.skia.org/infra/go/exec"
|
| + "go.skia.org/infra/go/swarming"
|
| "go.skia.org/infra/go/util"
|
|
|
| "github.com/skia-dev/glog"
|
| @@ -390,3 +391,48 @@ func ValidateSKPs(pathToSkps string) error {
|
|
|
| return nil
|
| }
|
| +
|
| +// GetStartRange returns the range worker should start processing at based on its num and how many
|
| +// artifacts it is allowed to process.
|
| +func GetStartRange(workerNum, artifactsPerWorker int) int {
|
| + return ((workerNum - 1) * artifactsPerWorker) + 1
|
| +}
|
| +
|
| +// ArchiveTriggerCollectSwarmingTasks is a convenience function for CT scripts to call to
|
| +// batch archive isolates, trigger swarming tasks, collect the triggered swarming tasks.
|
| +func ArchiveTriggerCollectSwarmingTask(s *swarming.SwarmingClient, taskNames, genJSONs []string, hardTimeout, ioTimeout time.Duration) error {
|
| + // Batcharchive the tasks.
|
| + tasksToHashes, err := s.BatchArchiveTargets(genJSONs, BATCHARCHIVE_TIMEOUT)
|
| + if err != nil {
|
| + return fmt.Errorf("Could not batch archive targets: %s", err)
|
| + }
|
| + if len(taskNames) != len(tasksToHashes) {
|
| + return fmt.Errorf("len(taskNames) was %d and len(tasksToHashes) was %d", len(taskNames), len(tasksToHashes))
|
| + }
|
| + // Trigger swarming using the isolate hashes.
|
| + dimensions := map[string]string{"pool": SWARMING_POOL}
|
| + tasks, err := s.TriggerSwarmingTasks(tasksToHashes, dimensions, swarming.RECOMMENDED_PRIORITY, swarming.RECOMMENDED_EXPIRATION, hardTimeout, ioTimeout, false)
|
| + if err != nil {
|
| + return fmt.Errorf("Could not trigger swarming task: %s", err)
|
| + }
|
| + // Collect all tasks and log the ones that fail.
|
| + for _, task := range tasks {
|
| + if _, _, err := task.Collect(s); err != nil {
|
| + glog.Errorf("task %s failed: %s", task.Title, err)
|
| + continue
|
| + }
|
| + }
|
| + return nil
|
| +}
|
| +
|
| +// GetPathToPyFiles returns the location of CT's python scripts.
|
| +func GetPathToPyFiles(runOnSwarming bool) string {
|
| + var pathToPyFiles string
|
| + if runOnSwarming {
|
| + pathToPyFiles = filepath.Join(filepath.Dir(filepath.Dir(os.Args[0])), "src", "go.skia.org", "infra", "ct", "py")
|
| + } else {
|
| + _, currentFile, _, _ := runtime.Caller(0)
|
| + pathToPyFiles = filepath.Join(filepath.Dir(filepath.Dir(filepath.Dir(currentFile))), "py")
|
| + }
|
| + return pathToPyFiles
|
| +}
|
|
|