MCPcopy Index your code
hub / github.com/coder/coder / claimPrebuild

Function claimPrebuild

coderd/workspaces.go:1021–1046  ·  view source on GitHub ↗
(
	ctx context.Context,
	claimer prebuilds.Claimer,
	db database.Store,
	logger slog.Logger,
	now time.Time,
	name string,
	owner workspaceOwner,
	templateVersionPresetID uuid.UUID,
	autostartSchedule sql.NullString,
	nextStartAt sql.NullTime,
	ttl sql.NullInt64,
)

Source from the content-addressed store, hash-verified

1019}
1020
1021func claimPrebuild(
1022 ctx context.Context,
1023 claimer prebuilds.Claimer,
1024 db database.Store,
1025 logger slog.Logger,
1026 now time.Time,
1027 name string,
1028 owner workspaceOwner,
1029 templateVersionPresetID uuid.UUID,
1030 autostartSchedule sql.NullString,
1031 nextStartAt sql.NullTime,
1032 ttl sql.NullInt64,
1033) (*database.Workspace, error) {
1034 claimedID, err := claimer.Claim(ctx, db, now, owner.ID, name, templateVersionPresetID, autostartSchedule, nextStartAt, ttl)
1035 if err != nil {
1036 // TODO: enhance this by clarifying whether this *specific* prebuild failed or whether there are none to claim.
1037 return nil, xerrors.Errorf("claim prebuild: %w", err)
1038 }
1039
1040 lookup, err := db.GetWorkspaceByID(ctx, *claimedID)
1041 if err != nil {
1042 logger.Error(ctx, "unable to find claimed workspace by ID", slog.Error(err), slog.F("claimed_prebuild_id", claimedID.String()))
1043 return nil, xerrors.Errorf("find claimed workspace by ID %q: %w", claimedID.String(), err)
1044 }
1045 return &lookup, nil
1046}
1047
1048func (api *API) notifyWorkspaceCreated(
1049 ctx context.Context,

Callers 3

TestReinitFunction · 0.85
createWorkspaceFunction · 0.85
TestPrebuildsAutobuildFunction · 0.85

Calls 5

ClaimMethod · 0.65
GetWorkspaceByIDMethod · 0.65
ErrorfMethod · 0.45
ErrorMethod · 0.45
StringMethod · 0.45

Tested by 2

TestReinitFunction · 0.68
TestPrebuildsAutobuildFunction · 0.68