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" ;
44import console from "node:console" ;
55import process from "node:process" ;
66import ora from "ora" ;
77import dayjs from "dayjs" ;
8- import { handleNodesError , nodesClient } from "../../nodesClient.ts" ;
8+ import { handleNodesError , nodesClient } from "../../nodesClient.ts" ;
99import {
1010 createNodesTable ,
1111 jsonOption ,
@@ -15,11 +15,11 @@ import {
1515 yesOption ,
1616} from "./utils.ts" ;
1717import 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
2424const extend = new Command ( "extend" )
2525 . description ( "Extend the duration of reserved nodes and update their pricing" )
@@ -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,7 +83,8 @@ async function extendNodeAction(
8383 if ( notFound . length > 0 ) {
8484 console . log (
8585 red (
86- `Could not find ${ notFound . length === 1 ? "this" : "these" } ${ pluralizeNodes ( notFound . length )
86+ `Could not find ${ notFound . length === 1 ? "this" : "these" } ${
87+ pluralizeNodes ( notFound . length )
8788 } :`,
8889 ) ,
8990 ) ;
@@ -94,22 +95,24 @@ async function extendNodeAction(
9495 }
9596
9697 // Filter out auto reserved nodes (they can't be extended)
97- const autoReservedNodes = nodes . filter ( ( { node} ) =>
98+ const autoReservedNodes = nodes . filter ( ( { node } ) =>
9899 node . node_type === "autoreserved"
99100 ) ;
100- const extendableNodes = nodes . filter ( ( { node} ) =>
101+ const extendableNodes = nodes . filter ( ( { node } ) =>
101102 node . node_type !== "autoreserved"
102103 ) ;
103104
104105 if ( autoReservedNodes . length > 0 ) {
105106 console . log (
106107 red (
107- `Cannot extend ${ autoReservedNodes . length === 1 ? "this" : "these"
108- } auto reserved ${ pluralizeNodes ( autoReservedNodes . length )
108+ `Cannot extend ${
109+ autoReservedNodes . length === 1 ? "this" : "these"
110+ } auto reserved ${
111+ pluralizeNodes ( autoReservedNodes . length )
109112 } (they auto-extend):`,
110113 ) ,
111114 ) ;
112- for ( const { name} of autoReservedNodes ) {
115+ for ( const { name } of autoReservedNodes ) {
113116 console . log ( ` • ${ name } ` ) ;
114117 }
115118 console . log (
@@ -138,8 +141,9 @@ async function extendNodeAction(
138141 ) ;
139142
140143 const selectedTime = await selectTime ( calculatedEndTime , {
141- message : `Nodes must be extended to an hour boundary. ${ cyan ( "Choose an end time:" )
142- } `,
144+ message : `Nodes must be extended to an hour boundary. ${
145+ cyan ( "Choose an end time:" )
146+ } `,
143147 } ) ;
144148
145149 if ( selectedTime === "NOW" ) {
@@ -173,7 +177,8 @@ async function extendNodeAction(
173177 if ( ! options . yes ) {
174178 // Get quote for accurate pricing preview
175179 const spinner = ora (
176- `Quoting extending ${ extendableNodes . length } ${ pluralizeNodes ( extendableNodes . length )
180+ `Quoting extending ${ extendableNodes . length } ${
181+ pluralizeNodes ( extendableNodes . length )
177182 } ...`,
178183 ) . start ( ) ;
179184
@@ -189,7 +194,7 @@ async function extendNodeAction(
189194 ) ;
190195
191196 const quotes = await Promise . allSettled (
192- extendableNodes . map ( async ( { node} ) => {
197+ extendableNodes . map ( async ( { node } ) => {
193198 return await getQuote ( {
194199 instanceType : `${ node . gpu_type . toLowerCase ( ) } v` as const ,
195200 quantity : 8 ,
@@ -208,8 +213,9 @@ async function extendNodeAction(
208213
209214 spinner . stop ( ) ;
210215
211- let confirmationMessage = `Extend ${ extendableNodes . length } ${ pluralizeNodes ( extendableNodes . length )
212- } for ${ formattedDuration } `;
216+ let confirmationMessage = `Extend ${ extendableNodes . length } ${
217+ pluralizeNodes ( extendableNodes . length )
218+ } for ${ formattedDuration } `;
213219
214220 // If there's only one node, show the price per node per hour
215221 if ( filteredQuotes . length === 1 && filteredQuotes [ 0 ] . value ) {
@@ -238,24 +244,25 @@ async function extendNodeAction(
238244 }
239245
240246 const spinner = ora (
241- `Extending ${ extendableNodes . length } ${ pluralizeNodes ( extendableNodes . length )
247+ `Extending ${ extendableNodes . length } ${
248+ pluralizeNodes ( extendableNodes . length )
242249 } ...`,
243250 ) . start ( ) ;
244251
245- const results : { name : string ; node : SFCNodes . Node } [ ] = [ ] ;
246- const errors : { name : string ; error : string } [ ] = [ ] ;
252+ const results : { name : string ; node : SFCNodes . Node } [ ] = [ ] ;
253+ const errors : { name : string ; error : string } [ ] = [ ] ;
247254
248- for ( const { name : nodeIdOrName , node : originalNode } of extendableNodes ) {
255+ for ( const { name : nodeIdOrName , node : originalNode } of extendableNodes ) {
249256 try {
250257 const extendedNode = await client . nodes . extend ( originalNode . id , {
251258 duration_seconds : options . duration ! ,
252259 max_price_per_node_hour : Math . round ( options . maxPrice * 100 ) ,
253260 } ) ;
254261
255- results . push ( { name : nodeIdOrName , node : extendedNode } ) ;
262+ results . push ( { name : nodeIdOrName , node : extendedNode } ) ;
256263 } catch ( err ) {
257264 const errorMsg = err instanceof Error ? err . message : "Unknown error" ;
258- errors . push ( { name : nodeIdOrName , error : errorMsg } ) ;
265+ errors . push ( { name : nodeIdOrName , error : errorMsg } ) ;
259266 }
260267 }
261268
@@ -266,7 +273,8 @@ async function extendNodeAction(
266273
267274 if ( results . length > 0 ) {
268275 spinner . succeed (
269- `Successfully extended ${ results . length } ${ pluralizeNodes ( results . length )
276+ `Successfully extended ${ results . length } ${
277+ pluralizeNodes ( results . length )
270278 } `,
271279 ) ;
272280 }
@@ -276,7 +284,8 @@ async function extendNodeAction(
276284 spinner . fail ( "Failed to extend any nodes" ) ;
277285 } else {
278286 spinner . warn (
279- `Extended ${ results . length } ${ pluralizeNodes ( results . length )
287+ `Extended ${ results . length } ${
288+ pluralizeNodes ( results . length )
280289 } , but ${ errors . length } failed`,
281290 ) ;
282291 }
0 commit comments