Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Side by Side Diff: perf/go/activitylog/activitylog.go

Issue 777413002: Add new tests to presubmit, fix errors (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: rebase Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « monitoring/go/prober/main.go ('k') | perf/go/alerting/alerting.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Package activitylog implements utility for activity logging into database. 1 // Package activitylog implements utility for activity logging into database.
2 package activitylog 2 package activitylog
3 3
4 import ( 4 import (
5 "fmt" 5 "fmt"
6 "time" 6 "time"
7 7
8 "github.com/golang/glog" 8 "github.com/golang/glog"
9 9
10 "skia.googlesource.com/buildbot.git/perf/go/db" 10 "skia.googlesource.com/buildbot.git/perf/go/db"
11 "skia.googlesource.com/buildbot.git/perf/go/types" 11 "skia.googlesource.com/buildbot.git/perf/go/types"
12 ) 12 )
13 13
14 // Write writes a new activity record to the db table activitylog. 14 // Write writes a new activity record to the db table activitylog.
15 // Input is in types.Activity format, but ID and TS are ignored. Instead, always 15 // Input is in types.Activity format, but ID and TS are ignored. Instead, always
16 // use autoincrement ID and the current timestamp for the new record. 16 // use autoincrement ID and the current timestamp for the new record.
17 func Write(r *types.Activity) error { 17 func Write(r *types.Activity) error {
18 glog.Infof("Write activity: %s\n", r) 18 glog.Infof("Write activity: %s\n", r)
19 if r.UserID == "" || r.Action == "" { 19 if r.UserID == "" || r.Action == "" {
20 » » return fmt.Errorf("Activity UserID and Action cannot be empty: % s\n", r) 20 » » return fmt.Errorf("Activity UserID and Action cannot be empty: % v\n", r)
21 } 21 }
22 _, err := db.DB.Exec( 22 _, err := db.DB.Exec(
23 "INSERT INTO activitylog (timestamp, userid, action, url) VALUES (?, ?, ?, ?)", 23 "INSERT INTO activitylog (timestamp, userid, action, url) VALUES (?, ?, ?, ?)",
24 time.Now().Unix(), r.UserID, r.Action, r.URL) 24 time.Now().Unix(), r.UserID, r.Action, r.URL)
25 if err != nil { 25 if err != nil {
26 return fmt.Errorf("Failed to write to database: %s", err) 26 return fmt.Errorf("Failed to write to database: %s", err)
27 } 27 }
28 return nil 28 return nil
29 } 29 }
30 30
(...skipping 20 matching lines...) Expand all
51 TS: timestamp, 51 TS: timestamp,
52 UserID: userid, 52 UserID: userid,
53 Action: action, 53 Action: action,
54 URL: url, 54 URL: url,
55 } 55 }
56 ret = append(ret, r) 56 ret = append(ret, r)
57 } 57 }
58 58
59 return ret, nil 59 return ret, nil
60 } 60 }
OLDNEW
« no previous file with comments | « monitoring/go/prober/main.go ('k') | perf/go/alerting/alerting.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698