Skip to content

Commit ee7c9e3

Browse files
committed
docs(nodes): use correct node-id format in extend example
1 parent 90f7042 commit ee7c9e3

File tree

1 file changed

+33
-42
lines changed

1 file changed

+33
-42
lines changed

src/lib/nodes/extend.ts

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { Command } from "@commander-js/extra-typings";
2-
import { confirm } from "@inquirer/prompts";
3-
import { brightRed, cyan, gray, red } from "jsr:@std/fmt/colors";
1+
import {Command} from "@commander-js/extra-typings";
2+
import {confirm} from "@inquirer/prompts";
3+
import {brightRed, cyan, gray, red} from "jsr:@std/fmt/colors";
44
import console from "node:console";
55
import process from "node:process";
66
import ora from "ora";
77
import dayjs from "dayjs";
8-
import { handleNodesError, nodesClient } from "../../nodesClient.ts";
8+
import {handleNodesError, nodesClient} from "../../nodesClient.ts";
99
import {
1010
createNodesTable,
1111
jsonOption,
@@ -15,11 +15,11 @@ import {
1515
yesOption,
1616
} from "./utils.ts";
1717
import SFCNodes from "@sfcompute/nodes-sdk-alpha";
18-
import { getPricePerGpuHourFromQuote, getQuote } from "../buy/index.tsx";
19-
import { GPUS_PER_NODE } from "../constants.ts";
20-
import { formatDuration } from "date-fns/formatDuration";
21-
import { intervalToDuration } from "date-fns/intervalToDuration";
22-
import { selectTime } from "../../helpers/units.ts";
18+
import {getPricePerGpuHourFromQuote, getQuote} from "../buy/index.tsx";
19+
import {GPUS_PER_NODE} from "../constants.ts";
20+
import {formatDuration} from "date-fns/formatDuration";
21+
import {intervalToDuration} from "date-fns/intervalToDuration";
22+
import {selectTime} from "../../helpers/units.ts";
2323

2424
const extend = new Command("extend")
2525
.description("Extend the duration of reserved nodes and update their pricing")
@@ -37,7 +37,7 @@ Examples:\n
3737
$ sf nodes extend my-node --duration 1h --max-price 15.00
3838
3939
\x1b[2m# Extend multiple nodes by node ID instead of name\x1b[0m
40-
$ sf nodes extend node-abc123 node-abc124 node-abc125 --duration 2h --max-price 10.00
40+
$ sf nodes extend n_b1dc52505c6db142 n_c1ed52505c6db142 --duration 2h --max-price 10.00
4141
4242
\x1b[2m# Extend with raw seconds\x1b[0m
4343
$ sf nodes extend my-node --duration 7200 --max-price 10.00
@@ -62,19 +62,19 @@ async function extendNodeAction(
6262
const fetchSpinner = ora().start(
6363
`Checking ${nodeNames.length} ${pluralizeNodes(nodeNames.length)}...`,
6464
);
65-
const { data: fetchedNodes } = await client.nodes.list({ name: nodeNames });
65+
const {data: fetchedNodes} = await client.nodes.list({name: nodeNames});
6666
fetchSpinner.stop();
6767

6868
// Check which names were not found
69-
const nodes: { name: string; node: SFCNodes.Node }[] = [];
69+
const nodes: {name: string; node: SFCNodes.Node}[] = [];
7070
const notFound: string[] = [];
7171

7272
for (const nameOrId of nodeNames) {
7373
const node = fetchedNodes.find((n) =>
7474
n.name === nameOrId || n.id === nameOrId
7575
);
7676
if (node) {
77-
nodes.push({ name: nameOrId, node });
77+
nodes.push({name: nameOrId, node});
7878
} else {
7979
notFound.push(nameOrId);
8080
}
@@ -83,8 +83,7 @@ async function extendNodeAction(
8383
if (notFound.length > 0) {
8484
console.log(
8585
red(
86-
`Could not find ${notFound.length === 1 ? "this" : "these"} ${
87-
pluralizeNodes(notFound.length)
86+
`Could not find ${notFound.length === 1 ? "this" : "these"} ${pluralizeNodes(notFound.length)
8887
}:`,
8988
),
9089
);
@@ -95,24 +94,22 @@ async function extendNodeAction(
9594
}
9695

9796
// Filter out auto reserved nodes (they can't be extended)
98-
const autoReservedNodes = nodes.filter(({ node }) =>
97+
const autoReservedNodes = nodes.filter(({node}) =>
9998
node.node_type === "autoreserved"
10099
);
101-
const extendableNodes = nodes.filter(({ node }) =>
100+
const extendableNodes = nodes.filter(({node}) =>
102101
node.node_type !== "autoreserved"
103102
);
104103

105104
if (autoReservedNodes.length > 0) {
106105
console.log(
107106
red(
108-
`Cannot extend ${
109-
autoReservedNodes.length === 1 ? "this" : "these"
110-
} auto reserved ${
111-
pluralizeNodes(autoReservedNodes.length)
107+
`Cannot extend ${autoReservedNodes.length === 1 ? "this" : "these"
108+
} auto reserved ${pluralizeNodes(autoReservedNodes.length)
112109
} (they auto-extend):`,
113110
),
114111
);
115-
for (const { name } of autoReservedNodes) {
112+
for (const {name} of autoReservedNodes) {
116113
console.log(` • ${name}`);
117114
}
118115
console.log(
@@ -141,9 +138,8 @@ async function extendNodeAction(
141138
);
142139

143140
const selectedTime = await selectTime(calculatedEndTime, {
144-
message: `Nodes must be extended to an hour boundary. ${
145-
cyan("Choose an end time:")
146-
}`,
141+
message: `Nodes must be extended to an hour boundary. ${cyan("Choose an end time:")
142+
}`,
147143
});
148144

149145
if (selectedTime === "NOW") {
@@ -177,8 +173,7 @@ async function extendNodeAction(
177173
if (!options.yes) {
178174
// Get quote for accurate pricing preview
179175
const spinner = ora(
180-
`Quoting extending ${extendableNodes.length} ${
181-
pluralizeNodes(extendableNodes.length)
176+
`Quoting extending ${extendableNodes.length} ${pluralizeNodes(extendableNodes.length)
182177
}...`,
183178
).start();
184179

@@ -194,7 +189,7 @@ async function extendNodeAction(
194189
);
195190

196191
const quotes = await Promise.allSettled(
197-
extendableNodes.map(async ({ node }) => {
192+
extendableNodes.map(async ({node}) => {
198193
return await getQuote({
199194
instanceType: `${node.gpu_type.toLowerCase()}v` as const,
200195
quantity: 8,
@@ -213,9 +208,8 @@ async function extendNodeAction(
213208

214209
spinner.stop();
215210

216-
let confirmationMessage = `Extend ${extendableNodes.length} ${
217-
pluralizeNodes(extendableNodes.length)
218-
} for ${formattedDuration}`;
211+
let confirmationMessage = `Extend ${extendableNodes.length} ${pluralizeNodes(extendableNodes.length)
212+
} for ${formattedDuration}`;
219213

220214
// If there's only one node, show the price per node per hour
221215
if (filteredQuotes.length === 1 && filteredQuotes[0].value) {
@@ -244,25 +238,24 @@ async function extendNodeAction(
244238
}
245239

246240
const spinner = ora(
247-
`Extending ${extendableNodes.length} ${
248-
pluralizeNodes(extendableNodes.length)
241+
`Extending ${extendableNodes.length} ${pluralizeNodes(extendableNodes.length)
249242
}...`,
250243
).start();
251244

252-
const results: { name: string; node: SFCNodes.Node }[] = [];
253-
const errors: { name: string; error: string }[] = [];
245+
const results: {name: string; node: SFCNodes.Node}[] = [];
246+
const errors: {name: string; error: string}[] = [];
254247

255-
for (const { name: nodeIdOrName, node: originalNode } of extendableNodes) {
248+
for (const {name: nodeIdOrName, node: originalNode} of extendableNodes) {
256249
try {
257250
const extendedNode = await client.nodes.extend(originalNode.id, {
258251
duration_seconds: options.duration!,
259252
max_price_per_node_hour: Math.round(options.maxPrice * 100),
260253
});
261254

262-
results.push({ name: nodeIdOrName, node: extendedNode });
255+
results.push({name: nodeIdOrName, node: extendedNode});
263256
} catch (err) {
264257
const errorMsg = err instanceof Error ? err.message : "Unknown error";
265-
errors.push({ name: nodeIdOrName, error: errorMsg });
258+
errors.push({name: nodeIdOrName, error: errorMsg});
266259
}
267260
}
268261

@@ -273,8 +266,7 @@ async function extendNodeAction(
273266

274267
if (results.length > 0) {
275268
spinner.succeed(
276-
`Successfully extended ${results.length} ${
277-
pluralizeNodes(results.length)
269+
`Successfully extended ${results.length} ${pluralizeNodes(results.length)
278270
}`,
279271
);
280272
}
@@ -284,8 +276,7 @@ async function extendNodeAction(
284276
spinner.fail("Failed to extend any nodes");
285277
} else {
286278
spinner.warn(
287-
`Extended ${results.length} ${
288-
pluralizeNodes(results.length)
279+
`Extended ${results.length} ${pluralizeNodes(results.length)
289280
}, but ${errors.length} failed`,
290281
);
291282
}

0 commit comments

Comments
 (0)