aboutsummaryrefslogtreecommitdiff
path: root/internal/postgres/versionstate.go
diff options
context:
space:
mode:
authorJulie Qiu <julie@golang.org>2020-02-18 17:46:24 -0500
committerJulie Qiu <julie@golang.org>2020-04-06 15:50:51 -0400
commit07a6612acfc56933213d98747dd1c65bd1da496a (patch)
tree4e3a394c237b989a86001bab3720bedd7acac961 /internal/postgres/versionstate.go
parent9f9b97d08b96983ce76e148da13cf59f35de3491 (diff)
downloadgo-x-pkgsite-07a6612acfc56933213d98747dd1c65bd1da496a.tar.xz
internal/{etl,postgres}: change type for module_version_states status and error
Previously, module_version_states.status and module_version_states.error were pointers. These are changed to type int and string, respectively, and will be set to not null field with default values of 0 and empty string in the next CL. This change makes it more ergonomic to work with these fields, while maintaining its behavior. Updates b/135954292 Change-Id: I3783c7a05259a787f57b5cb94299cc16174ffcee Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/669973 CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
Diffstat (limited to 'internal/postgres/versionstate.go')
-rw-r--r--internal/postgres/versionstate.go44
1 files changed, 12 insertions, 32 deletions
diff --git a/internal/postgres/versionstate.go b/internal/postgres/versionstate.go
index d7c96831..bf1095de 100644
--- a/internal/postgres/versionstate.go
+++ b/internal/postgres/versionstate.go
@@ -28,9 +28,9 @@ func (db *DB) InsertIndexVersions(ctx context.Context, versions []*internal.Inde
var vals []interface{}
for _, v := range versions {
- vals = append(vals, v.Path, v.Version, version.ForSorting(v.Version), v.Timestamp)
+ vals = append(vals, v.Path, v.Version, version.ForSorting(v.Version), v.Timestamp, 0, "")
}
- cols := []string{"module_path", "version", "sort_version", "index_timestamp"}
+ cols := []string{"module_path", "version", "sort_version", "index_timestamp", "status", "error"}
conflictAction := `
ON CONFLICT
(module_path, version)
@@ -52,9 +52,9 @@ func (db *DB) UpsertModuleVersionState(ctx context.Context, modulePath, vers, ap
defer span.End()
return db.db.Transact(func(tx *sql.Tx) error {
- var sqlErrorMsg sql.NullString
+ var sqlErrorMsg string
if fetchErr != nil {
- sqlErrorMsg = sql.NullString{Valid: true, String: fetchErr.Error()}
+ sqlErrorMsg = fetchErr.Error()
}
result, err := database.ExecTx(ctx, tx, `
@@ -193,34 +193,14 @@ const moduleVersionStateColumns = `
// scanner. It expects columns to be in the order of moduleVersionStateColumns.
func scanModuleVersionState(scan func(dest ...interface{}) error) (*internal.ModuleVersionState, error) {
var (
- modulePath, version, appVersion string
- indexTimestamp, createdAt, nextProcessedAfter time.Time
- lastProcessedAt pq.NullTime
- status sql.NullInt64
- errorMsg, goModPath sql.NullString
- tryCount int
+ v internal.ModuleVersionState
+ lastProcessedAt pq.NullTime
+ goModPath sql.NullString
)
- if err := scan(&modulePath, &version, &indexTimestamp, &createdAt, &status, &errorMsg,
- &tryCount, &lastProcessedAt, &nextProcessedAfter, &appVersion, &goModPath); err != nil {
+ if err := scan(&v.ModulePath, &v.Version, &v.IndexTimestamp, &v.CreatedAt, &v.Status, &v.Error,
+ &v.TryCount, &v.LastProcessedAt, &v.NextProcessedAfter, &v.AppVersion, &goModPath); err != nil {
return nil, err
}
- v := &internal.ModuleVersionState{
- ModulePath: modulePath,
- Version: version,
- IndexTimestamp: indexTimestamp,
- CreatedAt: createdAt,
- TryCount: tryCount,
- NextProcessedAfter: nextProcessedAfter,
- AppVersion: appVersion,
- }
- if status.Valid {
- s := int(status.Int64)
- v.Status = &s
- }
- if errorMsg.Valid {
- s := errorMsg.String
- v.Error = &s
- }
if goModPath.Valid {
s := goModPath.String
v.GoModPath = &s
@@ -229,7 +209,7 @@ func scanModuleVersionState(scan func(dest ...interface{}) error) (*internal.Mod
lp := lastProcessedAt.Time
v.LastProcessedAt = &lp
}
- return v, nil
+ return &v, nil
}
// queryModuleVersionStates executes a query for ModuleModuleVersionState rows. It expects the
@@ -291,7 +271,7 @@ func (db *DB) GetNextVersionsToFetch(ctx context.Context, limit int) (_ []*inter
AND
s.sort_version = m.max_sv
WHERE
- (status IS NULL OR status >= 500)
+ (status=0 OR status >= 500)
AND next_processed_after < CURRENT_TIMESTAMP
ORDER BY
s.sort_version DESC
@@ -310,7 +290,7 @@ func (db *DB) GetNextVersionsToFetch(ctx context.Context, limit int) (_ []*inter
FROM
module_version_states s
WHERE
- (status IS NULL OR status >= 500)
+ (status=0 OR status >= 500)
AND next_processed_after < CURRENT_TIMESTAMP
AND %[2]s (
module_path LIKE '%%/kubernetes'