Skip to content

Commit

Permalink
add forgiveness to buy order start date
Browse files Browse the repository at this point in the history
  • Loading branch information
Flaque committed Sep 9, 2024
1 parent 9a190b2 commit a748fbb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/lib/buy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ async function placeBuyOrderAction(options: SfBuyParamsNormalized) {
}
}

// If the user is requesting the order to be placed immediately,
// we need to set the start time to the current time
// to avoid causing any delay from quoting
if (!options.startsAt.wasSetByUser) {
options.startsAt = {
iso: new Date().toISOString(),
date: new Date(),
wasSetByUser: false
};
}
const { data: pendingOrder, err } = await placeBuyOrderRequest({
instance_type: options.instanceType,
quantity: options.totalNodes,
Expand Down Expand Up @@ -298,6 +308,7 @@ interface SfBuyParamsNormalized {
startsAt: {
iso: string;
date: Date;
wasSetByUser: boolean;
};
endsAt: {
iso: string;
Expand Down Expand Up @@ -348,6 +359,7 @@ function normalizeSfBuyOptions(options: SfBuyOptions): SfBuyParamsNormalized {
startsAt: {
iso: startDate.toISOString(),
date: startDate,
wasSetByUser: options.start !== undefined,
},
endsAt: {
iso: dayjs(startDate).add(durationSeconds, "s").toISOString(),
Expand Down

0 comments on commit a748fbb

Please sign in to comment.