Skip to content

Commit

Permalink
updates: Use the tx's methods to record updater's status (#647)
Browse files Browse the repository at this point in the history
This change makes sure all calls to modify the updater_status
table go through the transaction's connection instead of attempting
to acquire another one.

Signed-off-by: crozzy <[email protected]>
  • Loading branch information
crozzy authored Jul 5, 2022
1 parent b3f95ab commit df37f2a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/vulnstore/postgres/recordupdatetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ func recordUpdaterStatus(ctx context.Context, pool *pgxpool.Pool, updaterName st
zlog.Debug(ctx).
Str("updater", updaterName).
Msg("recording successful update")
_, err := pool.Exec(ctx, upsertSuccessfulUpdate, updaterName, updateTime, fingerprint)
_, err := tx.Exec(ctx, upsertSuccessfulUpdate, updaterName, updateTime, fingerprint)
if err != nil {
return fmt.Errorf("failed to upsert successful updater status: %w", err)
}
} else {
zlog.Debug(ctx).
Str("updater", updaterName).
Msg("recording failed update")
if err := pool.QueryRow(ctx, upsertFailedUpdate, updaterName, updateTime, fingerprint, updaterError.Error()).Scan(&returnedUpdaterName); err != nil {
if err := tx.QueryRow(ctx, upsertFailedUpdate, updaterName, updateTime, fingerprint, updaterError.Error()).Scan(&returnedUpdaterName); err != nil {
return fmt.Errorf("failed to upsert failed updater status: %w", err)
}
}
Expand Down Expand Up @@ -117,7 +117,7 @@ func recordUpdaterSetStatus(ctx context.Context, pool *pgxpool.Pool, updaterSet
}
defer tx.Rollback(ctx)

tag, err := pool.Exec(ctx, update, updateTime, updaterSet)
tag, err := tx.Exec(ctx, update, updateTime, updaterSet)
if err != nil {
return fmt.Errorf("failed to update updater statuses for updater set %s: %w", updaterSet, err)
}
Expand Down

0 comments on commit df37f2a

Please sign in to comment.