Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 182 additions & 0 deletions components/runpod/actions/create-pod/create-pod.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
import app from "../../runpod.app.mjs";
import mutations from "../../common/mutations.mjs";
import utils from "../../common/utils.mjs";

export default {
key: "runpod-create-pod",
name: "Create Pod",
description: "Creates a new pod with the specified parameters. [See the documentation](https://docs.runpod.io/sdks/graphql/manage-pods#create-spot-pod)",
version: "0.0.1",
type: "action",
props: {
app,
bidPerGpu: {
propDefinition: [
app,
"bidPerGpu",
],
},
cloudType: {
type: "string",
label: "Cloud Type",
description: "The type of cloud to use for the pod.",
options: [
"SECURE",
"COMMUNITY",
"ALL",
],
},
gpuCount: {
propDefinition: [
app,
"gpuCount",
],
},
volumeInGb: {
type: "integer",
label: "Volume In GB",
description: "The size of the volume in GB.",
},
containerDiskInGb: {
type: "integer",
label: "Container Disk In GB",
description: "The size of the container disk in GB.",
},
minVcpuCount: {
type: "integer",
label: "Minimum VCPU Count",
description: "The minimum number of VCPUs.",
},
minMemoryInGb: {
type: "integer",
label: "Minimum Memory In GB",
description: "The minimum memory size in GB.",
},
gpuTypeId: {
propDefinition: [
app,
"gpuTypeId",
],
},
name: {
type: "string",
label: "Name",
description: "The name of the pod.",
},
imageName: {
type: "string",
label: "Image Name",
description: "The name of the image to use for the pod.",
},
ports: {
type: "string",
label: "Ports",
description: "The ports to use for the pod.",
},
Comment on lines +71 to +75
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Clarify the expected format for 'Ports' property

The Ports property is defined as a string, but it's unclear how users should input the port values. Should it be a single port number, a comma-separated list, or another format? Please provide clear guidance in the description to help users enter the correct values.

Apply this diff to update the description:

-          description: "The ports to use for the pod.",
+          description: "The ports to use for the pod. Provide a comma-separated list of port numbers (e.g., '80,443,8080').",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ports: {
type: "string",
label: "Ports",
description: "The ports to use for the pod.",
},
ports: {
type: "string",
label: "Ports",
description: "The ports to use for the pod. Provide a comma-separated list of port numbers (e.g., '80,443,8080').",
},

volumeMountPath: {
type: "string",
label: "Volume Mount Path",
description: "The path where the volume will be mounted.",
},
env: {
type: "string[]",
label: "Environment Variables",
description: "The environment variables to set for the pod. Each row should be formated with JSON string like this `{\"key\": \"ENV_NAME\", \"value\": \"ENV_VALUE\"}`",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Typo in description: 'formated' should be 'formatted'

There's a typographical error in the description of the Environment Variables property. Please correct 'formated' to 'formatted'.

Apply this diff to fix the typo:

-          description: "The environment variables to set for the pod. Each row should be formated with JSON string like this `{\"key\": \"ENV_NAME\", \"value\": \"ENV_VALUE\"}`",
+          description: "The environment variables to set for the pod. Each row should be formatted with a JSON string like this `{\"key\": \"ENV_NAME\", \"value\": \"ENV_VALUE\"}`",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
description: "The environment variables to set for the pod. Each row should be formated with JSON string like this `{\"key\": \"ENV_NAME\", \"value\": \"ENV_VALUE\"}`",
description: "The environment variables to set for the pod. Each row should be formatted with a JSON string like this `{\"key\": \"ENV_NAME\", \"value\": \"ENV_VALUE\"}`",

optional: true,
},
Comment on lines +81 to +86
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve handling of 'Environment Variables' property to avoid parsing JSON strings

Currently, the Environment Variables property expects users to input JSON-formatted strings, which can be error-prone. Consider changing the property to accept key-value pairs directly, improving usability and reducing the likelihood of input errors.

Apply this refactor to change the Environment Variables property:

-      type: "string[]",
-      label: "Environment Variables",
-      description: "The environment variables to set for the pod. Each row should be formated with JSON string like this `{\"key\": \"ENV_NAME\", \"value\": \"ENV_VALUE\"}`",
-      optional: true,
+      type: "object[]",
+      label: "Environment Variables",
+      description: "The environment variables to set for the pod. Each item should be an object with 'key' and 'value' properties.",
+      optional: true,

Then, in your run method, you can use env directly without parsing:

-          env: utils.parseArray(env),
+          env,

Committable suggestion was skipped due to low confidence.

dockerArgs: {
type: "string",
label: "Docker Args",
description: "The arguments to pass to the docker command.",
optional: true,
},
startJupyter: {
type: "boolean",
label: "Start Jupyter",
description: "Whether to start Jupyter for the pod.",
optional: true,
},
startSsh: {
type: "boolean",
label: "Start SSH",
description: "Whether to start SSH for the pod.",
optional: true,
},
stopAfter: {
type: "string",
label: "Stop After",
description: "The duration after which the pod will be stopped.",
optional: true,
Comment on lines +106 to +109
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Clarify the expected format for 'Stop After' property

The Stop After property is of type string and represents the duration after which the pod will be stopped. Please specify the expected format for this duration (e.g., seconds, ISO 8601 duration) to help users provide the correct input.

Apply this diff to improve the description:

-          description: "The duration after which the pod will be stopped.",
+          description: "The duration in seconds after which the pod will be stopped (e.g., '3600' for 1 hour).",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
type: "string",
label: "Stop After",
description: "The duration after which the pod will be stopped.",
optional: true,
type: "string",
label: "Stop After",
description: "The duration in seconds after which the pod will be stopped (e.g., '3600' for 1 hour).",
optional: true,

},
supportPublicIp: {
type: "boolean",
label: "Support Public IP",
description: "Whether to support public IP for the pod.",
optional: true,
},
templateId: {
type: "string",
label: "Template ID",
description: "The ID of the template to use for the pod.",
optional: true,
},
},
methods: {
createPod(variables) {
return this.app.makeRequest({
query: mutations.createPod,
variables,
});
},
},
async run({ $ }) {
const {
createPod,
bidPerGpu,
cloudType,
gpuCount,
volumeInGb,
containerDiskInGb,
minVcpuCount,
minMemoryInGb,
gpuTypeId,
name,
imageName,
ports,
volumeMountPath,
env,
dockerArgs,
startJupyter,
startSsh,
stopAfter,
supportPublicIp,
templateId,
} = this;

const response = await createPod({
input: utils.cleanInput({
bidPerGpu,
cloudType,
gpuCount,
volumeInGb,
containerDiskInGb,
minVcpuCount,
minMemoryInGb,
gpuTypeId,
name,
imageName,
ports,
volumeMountPath,
env: utils.parseArray(env),
dockerArgs,
startJupyter,
startSsh,
stopAfter,
supportPublicIp,
templateId,
}),
});
$.export("$summary", `Successfully created a new pod with ID \`${response.id}\`.`);
return response;
},
};
42 changes: 42 additions & 0 deletions components/runpod/actions/get-pod/get-pod.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import app from "../../runpod.app.mjs";
import queries from "../../common/queries.mjs";

export default {
key: "runpod-get-pod",
name: "Get Pod Details",
description: "Get details of a pod by ID. [See the documentation](https://docs.runpod.io/sdks/graphql/manage-pods#get-pod-by-id).",
version: "0.0.1",
type: "action",
props: {
app,
podId: {
description: "The ID of the pod to get details for.",
propDefinition: [
app,
"podId",
],
},
},
methods: {
getPodDetails(variables) {
return this.app.makeRequest({
query: queries.getPod,
variables,
});
},
},
async run({ $ }) {
const {
getPodDetails,
podId,
} = this;

const response = await getPodDetails({
input: {
podId,
},
});
$.export("$summary", `Succesfully retrieved details for pod with ID \`${response.id}\`.`);
return response;
},
Comment on lines +28 to +41
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

LGTM: The run function is well-structured and follows best practices.

The async function is implemented correctly, using destructuring for improved readability. The API call and summary export provide the necessary functionality and user feedback.

There's a typo in the summary message. Please apply the following fix:

-    $.export("$summary", `Succesfully retrieved details for pod with ID \`${response.id}\`.`);
+    $.export("$summary", `Successfully retrieved details for pod with ID \`${response.id}\`.`);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async run({ $ }) {
const {
getPodDetails,
podId,
} = this;
const response = await getPodDetails({
input: {
podId,
},
});
$.export("$summary", `Succesfully retrieved details for pod with ID \`${response.id}\`.`);
return response;
},
async run({ $ }) {
const {
getPodDetails,
podId,
} = this;
const response = await getPodDetails({
input: {
podId,
},
});
$.export("$summary", `Successfully retrieved details for pod with ID \`${response.id}\`.`);
return response;
},

};
58 changes: 58 additions & 0 deletions components/runpod/actions/start-pod/start-pod.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import app from "../../runpod.app.mjs";
import mutations from "../../common/mutations.mjs";

export default {
key: "runpod-start-pod",
name: "Start Pod",
description: "Starts a stopped pod, making it available for use. [See the documentation](https://docs.runpod.io/sdks/graphql/manage-pods#start-spot-pod)",
version: "0.0.1",
type: "action",
props: {
app,
podId: {
propDefinition: [
app,
"podId",
],
},
gpuCount: {
propDefinition: [
app,
"gpuCount",
],
},
bidPerGpu: {
propDefinition: [
app,
"bidPerGpu",
],
},
},
methods: {
startPod(variables) {
return this.app.makeRequest({
query: mutations.startPod,
variables,
});
},
},
async run({ $ }) {
const {
startPod,
podId,
gpuCount,
bidPerGpu,
} = this;

const response = await startPod({
input: {
podId,
gpuCount,
bidPerGpu: parseFloat(bidPerGpu),
},
});

Comment on lines +47 to +54
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for the API request

The startPod API call may fail, and currently, potential errors are not being handled. Consider adding error handling to manage exceptions and provide meaningful feedback to the user.

You could wrap the API call in a try-catch block:

 async run({ $ }) {
   const {
     startPod,
     podId,
     gpuCount,
     bidPerGpu,
   } = this;

+  try {
     const response = await startPod({
       input: {
         podId,
         gpuCount,
         bidPerGpu: parseFloat(bidPerGpu),
       },
     });

     $.export("$summary", `Successfully started pod with ID \`${response.id}\`.`);
     return response;
+  } catch (error) {
+    $.export("$summary", "Failed to start pod.");
+    throw new Error(`Error starting pod: ${error.message}`);
+  }
 },

Committable suggestion was skipped due to low confidence.

$.export("$summary", `Sucessfully started pod with ID \`${response.id}\`.`);
return response;
},
};
52 changes: 52 additions & 0 deletions components/runpod/actions/stop-pod/stop-pod.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import app from "../../runpod.app.mjs";
import mutations from "../../common/mutations.mjs";

export default {
key: "runpod-stop-pod",
name: "Stop Pod",
description: "Stops a running pod, freeing up resources and preventing further charges. [See the documentation](https://docs.runpod.io/sdks/graphql/manage-pods#stop-pods)",
version: "0.0.1",
type: "action",
props: {
app,
podId: {
description: "The ID of the pod to stop.",
propDefinition: [
app,
"podId",
],
},
incrementVersion: {
type: "boolean",
label: "Increment Version",
description: "Whether to increment the pod version after stopping it.",
optional: true,
},
},
methods: {
stopPod(variables) {
return this.app.makeRequest({
query: mutations.stopPod,
variables,
});
},
},
async run({ $ }) {
const {
stopPod,
podId,
incrementVersion,
} = this;

const response = await stopPod({
input: {
podId,
incrementVersion,
},
});

$.export("$summary", `Succesfully stopped pod with ID \`${response.id}\`.`);

return response;
},
};
25 changes: 25 additions & 0 deletions components/runpod/common/mutations.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { gql } from "graphql-request";

export default {
createPod: gql`
mutation createPod($input: PodRentInterruptableInput!) {
podRentInterruptable(input: $input) {
id
}
}
`,
startPod: gql`
mutation startPod($input: PodBidResumeInput!) {
podResume(input: $input) {
id
}
}
`,
stopPod: gql`
mutation stopPod($input: PodStopInput!) {
podStop(input: $input) {
id
}
}
`,
};
Loading
Loading