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

Unified Diff: go/buildbot/db.go

Issue 813443002: Overhaul database package (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Unskip the CT GS tests 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 side-by-side diff with in-line comments
Download patch
Index: go/buildbot/db.go
diff --git a/go/buildbot/db.go b/go/buildbot/db.go
index 21d4eeff0f97d38563787ae65c817415cc7b9658..1ae2e64721c33bcbaf5426d32b5b82373e167971 100644
--- a/go/buildbot/db.go
+++ b/go/buildbot/db.go
@@ -4,6 +4,7 @@ import (
"database/sql"
"encoding/json"
"fmt"
+ "time"
)
// build from the database.
@@ -91,7 +92,19 @@ func GetBuildFromDB(master, builder string, buildNumber int) (*Build, error) {
}
// ReplaceIntoDB inserts or updates the Build in the database.
-func (b Build) ReplaceIntoDB() (rv error) {
+func (b Build) ReplaceIntoDB() error {
+ var err error
+ for attempt := 0; attempt < 5; attempt++ {
+ if err = b.replaceIntoDB(); err == nil {
+ return nil
+ }
+ time.Sleep(500 * time.Millisecond)
+ }
+ return err
+}
+
+// replaceIntoDB inserts or updates the Build in the database.
+func (b Build) replaceIntoDB() (rv error) {
// Insert the build itself.
tx, err := DB.Beginx()
if err != nil {
@@ -141,9 +154,9 @@ func (b Build) ReplaceIntoDB() (rv error) {
}
defer insertStepStmt.Close()
for _, s := range b.Steps {
- _, err = insertStepStmt.Exec(s.BuilderName, s.MasterName, s.BuildNumber, s.Name, s.Results, s.Number, s.Started, s.Finished)
+ _, err = insertStepStmt.Exec(b.BuilderName, b.MasterName, b.Number, s.Name, s.Results, s.Number, s.Started, s.Finished)
if err != nil {
- return fmt.Errorf("Failed to push build into database: %v", err)
+ return fmt.Errorf("Failed to push build step into database: %v", err)
}
}
« README.md ('K') | « go/buildbot/buildbot_test.go ('k') | go/buildbot/db_setup.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698