Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6a8cf69

Browse files
committed
untx
1 parent 3511274 commit 6a8cf69

File tree

1 file changed

+47
-54
lines changed

1 file changed

+47
-54
lines changed

coderd/provisionerdserver/provisionerdserver.go

Lines changed: 47 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,64 +1437,57 @@ func (s *server) CompleteJob(ctx context.Context, completed *proto.CompletedJob)
14371437
// If there is a plan, or a module files archive we need to insert a
14381438
// template_version_terraform_values row.
14391439
if len(plan) > 0 || len(moduleFiles) > 0 {
1440-
err := s.Database.InTx(func(tx database.Store) error {
1441-
// ...but the plan and the module files archive are both optional! So
1442-
// we need to fallback to a valid JSON object if the plan was omitted.
1443-
if len(plan) == 0 {
1444-
plan = []byte("{}")
1445-
}
1446-
1447-
// ...and we only want to insert a files row if an archive was provided.
1448-
var fileID uuid.NullUUID
1449-
if len(moduleFiles) > 0 {
1450-
hashBytes := sha256.Sum256(moduleFiles)
1451-
hash := hex.EncodeToString(hashBytes[:])
1452-
1453-
// nolint:gocritic // Requires reading "system" files
1454-
file, err := tx.GetFileByHashAndCreator(dbauthz.AsSystemRestricted(ctx), database.GetFileByHashAndCreatorParams{Hash: hash, CreatedBy: uuid.Nil})
1455-
switch {
1456-
case err == nil:
1457-
// This set of modules is already cached, which means we can reuse them
1458-
fileID = uuid.NullUUID{
1459-
Valid: true,
1460-
UUID: file.ID,
1461-
}
1462-
case !xerrors.Is(err, sql.ErrNoRows):
1463-
return xerrors.Errorf("check for cached modules: %w", err)
1464-
default:
1465-
// nolint:gocritic // Requires creating a "system" file
1466-
file, err = tx.InsertFile(dbauthz.AsSystemRestricted(ctx), database.InsertFileParams{
1467-
ID: uuid.New(),
1468-
Hash: hash,
1469-
CreatedBy: uuid.Nil,
1470-
CreatedAt: dbtime.Now(),
1471-
Mimetype: tarMimeType,
1472-
Data: moduleFiles,
1473-
})
1474-
if err != nil {
1475-
return xerrors.Errorf("insert template version terraform modules: %w", err)
1476-
}
1477-
fileID = uuid.NullUUID{
1478-
Valid: true,
1479-
UUID: file.ID,
1480-
}
1440+
// ...but the plan and the module files archive are both optional! So
1441+
// we need to fallback to a valid JSON object if the plan was omitted.
1442+
if len(plan) == 0 {
1443+
plan = []byte("{}")
1444+
}
1445+
1446+
// ...and we only want to insert a files row if an archive was provided.
1447+
var fileID uuid.NullUUID
1448+
if len(moduleFiles) > 0 {
1449+
hashBytes := sha256.Sum256(moduleFiles)
1450+
hash := hex.EncodeToString(hashBytes[:])
1451+
1452+
// nolint:gocritic // Requires reading "system" files
1453+
file, err := s.Database.GetFileByHashAndCreator(dbauthz.AsSystemRestricted(ctx), database.GetFileByHashAndCreatorParams{Hash: hash, CreatedBy: uuid.Nil})
1454+
switch {
1455+
case err == nil:
1456+
// This set of modules is already cached, which means we can reuse them
1457+
fileID = uuid.NullUUID{
1458+
Valid: true,
1459+
UUID: file.ID,
1460+
}
1461+
case !xerrors.Is(err, sql.ErrNoRows):
1462+
return nil, xerrors.Errorf("check for cached modules: %w", err)
1463+
default:
1464+
// nolint:gocritic // Requires creating a "system" file
1465+
file, err = s.Database.InsertFile(dbauthz.AsSystemRestricted(ctx), database.InsertFileParams{
1466+
ID: uuid.New(),
1467+
Hash: hash,
1468+
CreatedBy: uuid.Nil,
1469+
CreatedAt: dbtime.Now(),
1470+
Mimetype: tarMimeType,
1471+
Data: moduleFiles,
1472+
})
1473+
if err != nil {
1474+
return nil, xerrors.Errorf("insert template version terraform modules: %w", err)
1475+
}
1476+
fileID = uuid.NullUUID{
1477+
Valid: true,
1478+
UUID: file.ID,
14811479
}
14821480
}
1481+
}
14831482

1484-
err = tx.InsertTemplateVersionTerraformValuesByJobID(ctx, database.InsertTemplateVersionTerraformValuesByJobIDParams{
1485-
JobID: jobID,
1486-
UpdatedAt: now,
1487-
CachedPlan: plan,
1488-
CachedModuleFiles: fileID,
1489-
})
1490-
if err != nil {
1491-
return xerrors.Errorf("insert template version terraform data: %w", err)
1492-
}
1493-
1494-
return nil
1495-
}, nil)
1483+
err = s.Database.InsertTemplateVersionTerraformValuesByJobID(ctx, database.InsertTemplateVersionTerraformValuesByJobIDParams{
1484+
JobID: jobID,
1485+
UpdatedAt: now,
1486+
CachedPlan: plan,
1487+
CachedModuleFiles: fileID,
1488+
})
14961489
if err != nil {
1497-
return nil, err
1490+
return nil, xerrors.Errorf("insert template version terraform data: %w", err)
14981491
}
14991492
}
15001493

0 commit comments

Comments
 (0)