@@ -5,12 +5,11 @@ import (
5
5
"database/sql"
6
6
"errors"
7
7
8
- "github.com/coder/coder/v2/coderd/prebuilds"
9
-
10
8
"github.com/google/uuid"
11
9
"golang.org/x/xerrors"
12
10
13
11
"github.com/coder/coder/v2/coderd/database"
12
+ "github.com/coder/coder/v2/coderd/prebuilds"
14
13
)
15
14
16
15
type EnterpriseClaimer struct {}
@@ -22,39 +21,23 @@ func (_ EnterpriseClaimer) Claim(
22
21
name string ,
23
22
presetID uuid.UUID ,
24
23
) (* uuid.UUID , error ) {
25
- var prebuildID * uuid.UUID
26
- err := store .InTx (func (db database.Store ) error {
27
- // TODO: do we need this?
28
- //// Ensure no other replica can claim a prebuild for this user simultaneously.
29
- // err := store.AcquireLock(ctx, database.GenLockID(fmt.Sprintf("prebuild-user-claim-%s", userID.String())))
30
- // if err != nil {
31
- // return xerrors.Errorf("acquire claim lock for user %q: %w", userID.String(), err)
32
- //}
33
-
34
- result , err := db .ClaimPrebuiltWorkspace (ctx , database.ClaimPrebuiltWorkspaceParams {
35
- NewUserID : userID ,
36
- NewName : name ,
37
- PresetID : presetID ,
38
- })
39
- if err != nil {
40
- switch {
41
- // No eligible prebuilds found
42
- case errors .Is (err , sql .ErrNoRows ):
43
- // Exit, this will result in a nil prebuildID being returned, which is fine
44
- return nil
45
- default :
46
- return xerrors .Errorf ("claim prebuild for user %q: %w" , userID .String (), err )
47
- }
48
- }
49
-
50
- prebuildID = & result .ID
51
-
52
- return nil
53
- }, & database.TxOptions {
54
- TxIdentifier : "prebuild-claim" ,
24
+ result , err := store .ClaimPrebuiltWorkspace (ctx , database.ClaimPrebuiltWorkspaceParams {
25
+ NewUserID : userID ,
26
+ NewName : name ,
27
+ PresetID : presetID ,
55
28
})
29
+ if err != nil {
30
+ switch {
31
+ // No eligible prebuilds found
32
+ case errors .Is (err , sql .ErrNoRows ):
33
+ // Exit, this will result in a nil prebuildID being returned, which is fine
34
+ return nil , nil
35
+ default :
36
+ return nil , xerrors .Errorf ("claim prebuild for user %q: %w" , userID .String (), err )
37
+ }
38
+ }
56
39
57
- return prebuildID , err
40
+ return & result . ID , nil
58
41
}
59
42
60
43
func (_ EnterpriseClaimer ) Initiator () uuid.UUID {
0 commit comments