| OLD | NEW |
| 1 // Utility that contains methods for both CT master and worker scripts. | 1 // Utility that contains methods for both CT master and worker scripts. |
| 2 package util | 2 package util |
| 3 | 3 |
| 4 import ( | 4 import ( |
| 5 "bufio" | 5 "bufio" |
| 6 "encoding/json" |
| 6 "fmt" | 7 "fmt" |
| 7 "io" | 8 "io" |
| 8 "io/ioutil" | 9 "io/ioutil" |
| 9 "os" | 10 "os" |
| 10 "path/filepath" | 11 "path/filepath" |
| 11 "strconv" | 12 "strconv" |
| 12 "sync" | 13 "sync" |
| 13 "time" | 14 "time" |
| 14 | 15 |
| 15 "go.skia.org/infra/go/exec" | 16 "go.skia.org/infra/go/exec" |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 // happening chrome zombie processes are periodically killed. | 231 // happening chrome zombie processes are periodically killed. |
| 231 func ChromeProcessesCleaner(locker sync.Locker, chromeCleanerTimer time.Duration
) { | 232 func ChromeProcessesCleaner(locker sync.Locker, chromeCleanerTimer time.Duration
) { |
| 232 for _ = range time.Tick(chromeCleanerTimer) { | 233 for _ = range time.Tick(chromeCleanerTimer) { |
| 233 glog.Info("The chromeProcessesCleaner goroutine has started") | 234 glog.Info("The chromeProcessesCleaner goroutine has started") |
| 234 glog.Info("Waiting for all existing tasks to complete before kil
ling zombie chrome processes") | 235 glog.Info("Waiting for all existing tasks to complete before kil
ling zombie chrome processes") |
| 235 locker.Lock() | 236 locker.Lock() |
| 236 util.LogErr(ExecuteCmd("pkill", []string{"-9", "chrome"}, []stri
ng{}, PKILL_TIMEOUT, nil, nil)) | 237 util.LogErr(ExecuteCmd("pkill", []string{"-9", "chrome"}, []stri
ng{}, PKILL_TIMEOUT, nil, nil)) |
| 237 locker.Unlock() | 238 locker.Unlock() |
| 238 } | 239 } |
| 239 } | 240 } |
| 241 |
| 242 // Contains the data included in CT pagesets. |
| 243 type PagesetVars struct { |
| 244 // A comma separated list of URLs. |
| 245 UrlsList string `json:"urls_list"` |
| 246 // Will be either "mobile" or "desktop". |
| 247 UserAgent string `json:"user_agent"` |
| 248 // The location of the web page's WPR data file. |
| 249 ArchiveDataFile string `json:"archive_data_file"` |
| 250 } |
| 251 |
| 252 func ReadPageset(pagesetPath string) (PagesetVars, error) { |
| 253 decodedPageset := PagesetVars{} |
| 254 pagesetContent, err := os.Open(pagesetPath) |
| 255 if err != nil { |
| 256 return decodedPageset, fmt.Errorf("Could not read %s: %s", pages
etPath, err) |
| 257 } |
| 258 if err := json.NewDecoder(pagesetContent).Decode(&decodedPageset); err !
= nil { |
| 259 return decodedPageset, fmt.Errorf("Could not JSON decode %s: %s"
, pagesetPath, err) |
| 260 } |
| 261 return decodedPageset, nil |
| 262 } |
| OLD | NEW |