OLD | NEW |
1 // capture_archives_on_workers is an application that captures archives on all C
T | 1 // capture_archives_on_workers is an application that captures archives on all C
T |
2 // workers and uploads it to Google Storage. The requester is emailed when the t
ask | 2 // workers and uploads it to Google Storage. The requester is emailed when the t
ask |
3 // is done. | 3 // is done. |
4 package main | 4 package main |
5 | 5 |
6 import ( | 6 import ( |
7 "flag" | 7 "flag" |
8 "fmt" | 8 "fmt" |
9 » "strings" | 9 » "path/filepath" |
10 "time" | 10 "time" |
11 | 11 |
12 "github.com/skia-dev/glog" | 12 "github.com/skia-dev/glog" |
13 "go.skia.org/infra/ct/go/ctfe/admin_tasks" | 13 "go.skia.org/infra/ct/go/ctfe/admin_tasks" |
14 "go.skia.org/infra/ct/go/frontend" | 14 "go.skia.org/infra/ct/go/frontend" |
15 "go.skia.org/infra/ct/go/master_scripts/master_common" | 15 "go.skia.org/infra/ct/go/master_scripts/master_common" |
16 "go.skia.org/infra/ct/go/util" | 16 "go.skia.org/infra/ct/go/util" |
17 "go.skia.org/infra/go/common" | 17 "go.skia.org/infra/go/common" |
18 skutil "go.skia.org/infra/go/util" | 18 skutil "go.skia.org/infra/go/util" |
19 ) | 19 ) |
20 | 20 |
21 var ( | 21 var ( |
22 emails = flag.String("emails", "", "The comma separated email addre
sses to notify when the task is picked up and completes.") | 22 emails = flag.String("emails", "", "The comma separated email addre
sses to notify when the task is picked up and completes.") |
23 gaeTaskID = flag.Int64("gae_task_id", -1, "The key of the App Engine t
ask. This task will be updated when the task is completed.") | 23 gaeTaskID = flag.Int64("gae_task_id", -1, "The key of the App Engine t
ask. This task will be updated when the task is completed.") |
24 pagesetType = flag.String("pageset_type", "", "The type of pagesets to u
se. Eg: 10k, Mobile10k, All.") | 24 pagesetType = flag.String("pageset_type", "", "The type of pagesets to u
se. Eg: 10k, Mobile10k, All.") |
25 runID = flag.String("run_id", "", "The unique run id (typically re
quester + timestamp).") | 25 runID = flag.String("run_id", "", "The unique run id (typically re
quester + timestamp).") |
26 | 26 |
27 taskCompletedSuccessfully = new(bool) | 27 taskCompletedSuccessfully = new(bool) |
28 ) | 28 ) |
29 | 29 |
| 30 const ( |
| 31 MAX_PAGES_PER_SWARMING_BOT = 10 |
| 32 ) |
| 33 |
30 func sendEmail(recipients []string) { | 34 func sendEmail(recipients []string) { |
31 // Send completion email. | 35 // Send completion email. |
32 emailSubject := "Capture archives Cluster telemetry task has completed" | 36 emailSubject := "Capture archives Cluster telemetry task has completed" |
33 failureHtml := "" | 37 failureHtml := "" |
34 if !*taskCompletedSuccessfully { | 38 if !*taskCompletedSuccessfully { |
35 emailSubject += " with failures" | 39 emailSubject += " with failures" |
36 failureHtml = util.GetFailureEmailHtml(*runID) | 40 failureHtml = util.GetFailureEmailHtml(*runID) |
37 } | 41 } |
38 bodyTemplate := ` | 42 bodyTemplate := ` |
39 The Cluster telemetry queued task to capture archives of %s pagesets has
completed.<br/> | 43 The Cluster telemetry queued task to capture archives of %s pagesets has
completed.<br/> |
(...skipping 24 matching lines...) Expand all Loading... |
64 emailsArr = append(emailsArr, util.CtAdmins...) | 68 emailsArr = append(emailsArr, util.CtAdmins...) |
65 if len(emailsArr) == 0 { | 69 if len(emailsArr) == 0 { |
66 glog.Error("At least one email address must be specified") | 70 glog.Error("At least one email address must be specified") |
67 return | 71 return |
68 } | 72 } |
69 skutil.LogErr(frontend.UpdateWebappTaskSetStarted(&admin_tasks.RecreateW
ebpageArchivesUpdateVars{}, *gaeTaskID)) | 73 skutil.LogErr(frontend.UpdateWebappTaskSetStarted(&admin_tasks.RecreateW
ebpageArchivesUpdateVars{}, *gaeTaskID)) |
70 skutil.LogErr(util.SendTaskStartEmail(emailsArr, "Capture archives", *ru
nID, "")) | 74 skutil.LogErr(util.SendTaskStartEmail(emailsArr, "Capture archives", *ru
nID, "")) |
71 // Ensure webapp is updated and completion email is sent even if task fa
ils. | 75 // Ensure webapp is updated and completion email is sent even if task fa
ils. |
72 defer updateWebappTask() | 76 defer updateWebappTask() |
73 defer sendEmail(emailsArr) | 77 defer sendEmail(emailsArr) |
74 if !*master_common.Local { | |
75 // Cleanup tmp files after the run. | |
76 defer util.CleanTmpDir() | |
77 } | |
78 // Finish with glog flush and how long the task took. | 78 // Finish with glog flush and how long the task took. |
79 defer util.TimeTrack(time.Now(), "Capture archives on Workers") | 79 defer util.TimeTrack(time.Now(), "Capture archives on Workers") |
80 defer glog.Flush() | 80 defer glog.Flush() |
81 | 81 |
82 if *pagesetType == "" { | 82 if *pagesetType == "" { |
83 glog.Error("Must specify --pageset_type") | 83 glog.Error("Must specify --pageset_type") |
84 return | 84 return |
85 } | 85 } |
86 | 86 |
87 » cmd := append(master_common.WorkerSetupCmds(), | 87 » // Empty the remote dir before the workers upload to it. |
88 » » // The main command that runs capture_archives on all workers. | 88 » gs, err := util.NewGsUtil(nil) |
89 » » fmt.Sprintf("DISPLAY=:0 capture_archives --worker_num=%s --log_d
ir=%s --log_id=%s --pageset_type=%s --local=%t;", util.WORKER_NUM_KEYWORD, util.
GLogDir, *runID, *pagesetType, *master_common.Local)) | |
90 | |
91 » _, err := util.SSH(strings.Join(cmd, " "), util.Slaves, util.CAPTURE_ARC
HIVES_TIMEOUT) | |
92 if err != nil { | 89 if err != nil { |
93 » » glog.Errorf("Error while running cmd %s: %s", cmd, err) | 90 » » glog.Error(err) |
94 return | 91 return |
95 } | 92 } |
| 93 gsBaseDir := filepath.Join(util.SWARMING_DIR_NAME, util.WEB_ARCHIVES_DIR
_NAME, *pagesetType) |
| 94 skutil.LogErr(gs.DeleteRemoteDir(gsBaseDir)) |
| 95 |
| 96 // Archive, trigger and collect swarming tasks. |
| 97 if err := util.TriggerSwarmingTask(*pagesetType, "capture_archives", uti
l.CAPTURE_ARCHIVES_ISOLATE, 2*time.Hour, 1*time.Hour, MAX_PAGES_PER_SWARMING_BOT
, map[string]string{}); err != nil { |
| 98 glog.Errorf("Error encountered when swarming tasks: %s", err) |
| 99 return |
| 100 } |
| 101 |
96 *taskCompletedSuccessfully = true | 102 *taskCompletedSuccessfully = true |
97 } | 103 } |
OLD | NEW |