| 1019 | } |
| 1020 | |
| 1021 | func 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 | |
| 1048 | func (api *API) notifyWorkspaceCreated( |
| 1049 | ctx context.Context, |