@@ -11,7 +11,6 @@ import (
11
11
"time"
12
12
13
13
"github.com/google/uuid"
14
- "github.com/lib/pq"
15
14
"github.com/sqlc-dev/pqtype"
16
15
"golang.org/x/xerrors"
17
16
@@ -210,29 +209,17 @@ func (b *Builder) Build(
210
209
// RepeatableRead isolation ensures that we get a consistent view of the database while
211
210
// computing the new build. This simplifies the logic so that we do not need to worry if
212
211
// later reads are consistent with earlier ones.
213
- var err error
214
- for retries := 0 ; retries < 5 ; retries ++ {
215
- var workspaceBuild * database.WorkspaceBuild
216
- var provisionerJob * database.ProvisionerJob
217
- err := store .InTx (func (store database.Store ) error {
218
- b .store = store
219
- workspaceBuild , provisionerJob , err = b .buildTx (authFunc )
220
- return err
221
- }, & sql.TxOptions {Isolation : sql .LevelRepeatableRead })
222
- var pqe * pq.Error
223
- if xerrors .As (err , & pqe ) {
224
- if pqe .Code == "40001" {
225
- // serialization error, retry
226
- continue
227
- }
228
- }
229
- if err != nil {
230
- // Other (hard) error
231
- return nil , nil , err
232
- }
233
- return workspaceBuild , provisionerJob , nil
212
+ var workspaceBuild * database.WorkspaceBuild
213
+ var provisionerJob * database.ProvisionerJob
214
+ err := database .ReadModifyUpdate (store , func (tx database.Store ) error {
215
+ var err error
216
+ workspaceBuild , provisionerJob , err = b .buildTx (authFunc )
217
+ return err
218
+ })
219
+ if err != nil {
220
+ return nil , nil , xerrors .Errorf ("too many errors; last error: %w" , err )
234
221
}
235
- return nil , nil , xerrors . Errorf ( "too many errors; last error: %w" , err )
222
+ return workspaceBuild , provisionerJob , nil
236
223
}
237
224
238
225
// buildTx contains the business logic of computing a new build. Attributes of the new database objects are computed
0 commit comments