Skip to content

Commit 37de101

Browse files
committed
add coupon redemption
1 parent 05fc089 commit 37de101

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

pkg/cmd/gpucreate/gpucreate.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ type GPUCreateStore interface {
103103
DeleteWorkspace(workspaceID string) (*entity.Workspace, error)
104104
GetAllInstanceTypesWithWorkspaceGroups(orgID string) (*gpusearch.AllInstanceTypesResponse, error)
105105
GetLaunchable(launchableID string) (*store.LaunchableResponse, error)
106+
RedeemCouponCode(organizationID string, code string) (*store.RedeemCouponCodeResponse, error)
106107
}
107108

108109
// Default filter values for automatic GPU selection
@@ -909,6 +910,13 @@ func RunGPUCreate(t *terminal.Terminal, gpuCreateStore GPUCreateStore, opts GPUC
909910
return err
910911
}
911912

913+
// Auto-redeem coupon code if the launchable has one attached.
914+
// This is silent — the UI doesn't surface coupon redemption to the user either.
915+
// Failures are ignored; the coupon may already be redeemed.
916+
if opts.LaunchableInfo != nil && opts.LaunchableInfo.CouponCode != "" {
917+
_, _ = gpuCreateStore.RedeemCouponCode(ctx.org.ID, opts.LaunchableInfo.CouponCode)
918+
}
919+
912920
ctx.logf("Attempting to create %d instance(s) with %d parallel attempts\n", opts.Count, opts.Parallel)
913921
ctx.logf("Instance types to try: %s\n\n", formatInstanceSpecs(opts.InstanceTypes))
914922

pkg/cmd/gpucreate/gpucreate_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ func (m *MockGPUCreateStore) GetLaunchable(launchableID string) (*store.Launchab
105105
}, nil
106106
}
107107

108+
func (m *MockGPUCreateStore) RedeemCouponCode(organizationID string, code string) (*store.RedeemCouponCodeResponse, error) {
109+
return &store.RedeemCouponCodeResponse{}, nil
110+
}
111+
108112
func (m *MockGPUCreateStore) GetInstanceTypes(_ bool) (*gpusearch.InstanceTypesResponse, error) {
109113
// Return a default set of instance types for testing
110114
return &gpusearch.InstanceTypesResponse{

pkg/store/workspace.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ type LaunchableResponse struct {
126126
CreatedByUserID string `json:"createdByUserId"`
127127
CreatedByOrgID string `json:"createdByOrgId"`
128128
File *LaunchableFile `json:"file,omitempty"`
129+
CouponCode string `json:"couponCode,omitempty"`
129130
}
130131

131132
type LaunchableWorkspaceRequest struct {

0 commit comments

Comments
 (0)