-
Notifications
You must be signed in to change notification settings - Fork 3
Add sf extend #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
joshi4
merged 3 commits into
main
from
shantanu/metal-36-add-sf-extend-command-to-set-start-time-for-contracts
Apr 17, 2025
Merged
Add sf extend #117
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import { type Command } from "@commander-js/extra-typings"; | ||
| import { render } from "ink"; | ||
| import dayjs from "npm:dayjs@1.11.13"; | ||
| import duration from "npm:dayjs@1.11.13/plugin/duration.js"; | ||
| import relativeTime from "npm:dayjs@1.11.13/plugin/relativeTime.js"; | ||
| import { parseDuration, SfBuyOptions } from "../buy/index.tsx"; | ||
| import React from "react"; | ||
| import { getContract } from "../../helpers/fetchers.ts"; | ||
| import { logAndQuit } from "../../helpers/errors.ts"; | ||
| import { QuoteAndBuy, QuoteComponent } from "../buy/index.tsx"; | ||
| import { ActiveContract } from "../contracts/types.ts"; | ||
| import { GPUS_PER_NODE } from "../constants.ts"; | ||
| import { | ||
| getContractAcceleratorQuantity, | ||
| getContractRange, | ||
| } from "../contracts/utils.ts"; | ||
|
|
||
| dayjs.extend(relativeTime); | ||
| dayjs.extend(duration); | ||
|
|
||
| function _registerExtend(program: Command) { | ||
| return program | ||
| .command("extend") | ||
| .description("Extend an existing contract") | ||
| .requiredOption( | ||
| "-c, --contract <contract>", | ||
| "Contract ID to extend e.g. cont_a9IcKaLesUBTHEY", | ||
| ) | ||
| .requiredOption( | ||
| "-d, --duration <duration>", | ||
| "Extension duration (rounded up to the nearest hour)", | ||
| parseDuration, | ||
| ) | ||
| .option("-p, --price <price>", "Price in dollars per GPU hour") | ||
| .option("-y, --yes", "Automatically confirm the extension") | ||
| .option( | ||
| "-q, --quote", | ||
| "Get a price quote without placing an extension order", | ||
| ) | ||
| .configureHelp({ | ||
| optionDescription: (option) => { | ||
| if (option.flags === "-h, --help") { | ||
| return "Display help for extend"; | ||
| } | ||
| return option.description; | ||
| }, | ||
| }) | ||
| .addHelpText( | ||
| "after", | ||
| ` | ||
| Examples: | ||
| \x1b[2m# Get a Quote to extend a contract for 1 hour\x1b[0m] | ||
| $ sf extend --contract <contract_id> --duration 1h --quote | ||
|
|
||
| \x1b[2m# Auto confirm extending a contract by 1 hour at market price\x1b[0m] | ||
| $ sf extend -c <contract_id> -d 1h --yes | ||
|
|
||
| \x1b[2m# Extend a contract for 2 hours at a specific price\x1b[0m] | ||
| $ sf extend -c <contract_id> -d 2h --price 1.50 | ||
| `, | ||
| ) | ||
| .action(async function extendAction(options) { | ||
| const contract = await getContract(options.contract); | ||
| if (!contract) { | ||
| logAndQuit(`Contract ${options.contract} not found`); | ||
| } | ||
|
|
||
| if (contract.status !== "active") { | ||
| logAndQuit( | ||
| `Contract ${contract.id} is ${contract.status}. Only active contracts can be extended.`, | ||
| ); | ||
| } | ||
|
|
||
| const activeContract = contract as ActiveContract; | ||
| const activeContractRange = getContractRange(activeContract.shape); | ||
|
|
||
| const quoteOptions: SfBuyOptions = { | ||
| type: activeContract.instance_type, | ||
| accelerators: getContractAcceleratorQuantity(activeContract.shape) * | ||
| GPUS_PER_NODE, | ||
| colocate: [activeContract.id], | ||
| duration: options.duration, | ||
| price: options.price, | ||
| start: activeContractRange.endsAt, | ||
| quote: options.quote, | ||
| yes: options.yes, | ||
| }; | ||
|
|
||
| if (options.quote) { | ||
| render(<QuoteComponent options={quoteOptions} />); | ||
| } | ||
| render(<QuoteAndBuy options={quoteOptions} />); | ||
| }); | ||
| } | ||
|
|
||
| export function registerExtend(program: Command) { | ||
| _registerExtend(program); | ||
| } | ||
|
Comment on lines
+96
to
+98
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bit confused on why you didn't just export registerExtend directly here? |
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.