-
Notifications
You must be signed in to change notification settings - Fork 9
feat(sdk): warm pool management across typescript, python, go, ruby and java sdks #145
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
Open
brunogrbavac
wants to merge
1
commit into
main
Choose a base branch
from
feat/warm-pools
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "log" | ||
|
|
||
| "github.com/daytona/clients/sdk-go/pkg/daytona" | ||
| "github.com/daytona/clients/sdk-go/pkg/types" | ||
| ) | ||
|
|
||
| func main() { | ||
| // Create a new Daytona client using environment variables. | ||
| // Set DAYTONA_API_KEY before running. | ||
| client, err := daytona.NewClient() | ||
| if err != nil { | ||
| log.Fatalf("Failed to create client: %v", err) | ||
| } | ||
|
|
||
| ctx := context.Background() | ||
|
|
||
| // Create a warm pool that keeps ready-to-use sandboxes for an existing snapshot. | ||
| // Target is optional and defaults to the organization default region. | ||
| pool, err := client.WarmPool.Create(ctx, &types.CreateWarmPoolParams{ | ||
| Snapshot: "my-snapshot", | ||
| Pool: 3, | ||
| }) | ||
| if err != nil { | ||
| log.Fatalf("Failed to create warm pool: %v", err) | ||
| } | ||
| log.Printf("✓ Created warm pool %s for snapshot %q in %s\n", pool.ID, pool.Snapshot, pool.Target) | ||
|
|
||
| // List warm pools. CurrentSize vs Pool is the status check: CurrentSize is the | ||
| // number of ready sandboxes; ErrorReason is set when the pool cannot be filled. | ||
| pools, err := client.WarmPool.List(ctx) | ||
| if err != nil { | ||
| log.Fatalf("Failed to list warm pools: %v", err) | ||
| } | ||
| for _, p := range pools { | ||
| status := "" | ||
| if p.ErrorReason != nil { | ||
| status = " (error: " + *p.ErrorReason + ")" | ||
| } | ||
| log.Printf("%s (%s): %d/%d ready%s\n", p.Snapshot, p.Target, p.CurrentSize, p.Pool, status) | ||
| } | ||
|
|
||
| // Grow the pool. Setting the size to 0 drains it without deleting the pool. | ||
| updated, err := client.WarmPool.Update(ctx, pool.ID, 5) | ||
| if err != nil { | ||
| log.Fatalf("Failed to update warm pool: %v", err) | ||
| } | ||
| log.Printf("✓ Updated desired size to %d\n", updated.Pool) | ||
|
|
||
| // Cleanup | ||
| if err := client.WarmPool.Delete(ctx, pool.ID); err != nil { | ||
| log.Fatalf("Failed to delete warm pool: %v", err) | ||
| } | ||
| log.Println("✓ Deleted warm pool") | ||
| } |
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,24 @@ | ||
| plugins { | ||
| application | ||
| } | ||
|
|
||
| group = "io.daytona.examples" | ||
| version = "0.1.0" | ||
|
|
||
| java { | ||
| sourceCompatibility = JavaVersion.VERSION_11 | ||
| targetCompatibility = JavaVersion.VERSION_11 | ||
| } | ||
|
|
||
| repositories { | ||
| mavenLocal() | ||
| mavenCentral() | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation("io.daytona:sdk-java") | ||
| } | ||
|
|
||
| application { | ||
| mainClass.set("io.daytona.examples.WarmPools") | ||
| } |
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,14 @@ | ||
| rootProject.name = "warm-pools" | ||
|
|
||
| dependencyResolutionManagement { | ||
| repositories { | ||
| mavenLocal() | ||
| mavenCentral() | ||
| } | ||
| } | ||
|
|
||
| includeBuild("../../../sdk-java") { | ||
| dependencySubstitution { | ||
| substitute(module("io.daytona:sdk-java")).using(project(":")) | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
examples/java/warm-pools/src/main/java/io/daytona/examples/WarmPools.java
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,32 @@ | ||
| package io.daytona.examples; | ||
|
|
||
| import io.daytona.sdk.Daytona; | ||
| import io.daytona.sdk.model.WarmPool; | ||
|
|
||
| public class WarmPools { | ||
| public static void main(String[] args) { | ||
| try (Daytona daytona = new Daytona()) { | ||
| // Create a warm pool that keeps ready-to-use sandboxes for an existing snapshot. | ||
| // The target (third argument) is optional; null means the organization default region. | ||
| WarmPool pool = daytona.warmPool().create("my-snapshot", 3, null); | ||
| System.out.println("Created warm pool " + pool.getId() | ||
| + " for snapshot '" + pool.getSnapshot() + "' in " + pool.getTarget()); | ||
|
|
||
| // List warm pools. currentSize vs pool is the status check: currentSize is the | ||
| // number of ready sandboxes; errorReason is set when the pool cannot be filled. | ||
| for (WarmPool p : daytona.warmPool().list()) { | ||
| String status = p.getErrorReason() != null ? " (error: " + p.getErrorReason() + ")" : ""; | ||
| System.out.println(p.getSnapshot() + " (" + p.getTarget() + "): " | ||
| + p.getCurrentSize() + "/" + p.getPool() + " ready" + status); | ||
| } | ||
|
|
||
| // Grow the pool. Setting the size to 0 drains it without deleting the pool. | ||
| WarmPool updated = daytona.warmPool().update(pool.getId(), 5); | ||
| System.out.println("Updated desired size to " + updated.getPool()); | ||
|
|
||
| // Cleanup | ||
| daytona.warmPool().delete(pool.getId()); | ||
| System.out.println("Deleted warm pool"); | ||
| } | ||
| } | ||
| } | ||
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,29 @@ | ||
| import asyncio | ||
|
|
||
| from daytona import AsyncDaytona | ||
|
|
||
|
|
||
| async def main(): | ||
| async with AsyncDaytona() as daytona: | ||
| # Create a warm pool that keeps ready-to-use sandboxes for an existing snapshot. | ||
| # `target` is optional and defaults to the organization default region. | ||
| pool = await daytona.warm_pool.create("my-snapshot", pool=3) | ||
| print(f"Created warm pool {pool.id} for snapshot '{pool.snapshot}' in {pool.target}") | ||
|
|
||
| # List warm pools. current_size vs pool is the status check: current_size is the | ||
| # number of ready sandboxes; error_reason is set when the pool cannot be filled. | ||
| for p in await daytona.warm_pool.list(): | ||
| status = f" (error: {p.error_reason})" if p.error_reason else "" | ||
| print(f"{p.snapshot} ({p.target}): {p.current_size}/{p.pool} ready{status}") | ||
|
|
||
| # Grow the pool. Setting pool to 0 drains it without deleting the pool. | ||
| updated = await daytona.warm_pool.update(pool.id, pool=5) | ||
| print(f"Updated desired size to {updated.pool}") | ||
|
|
||
| # Cleanup | ||
| await daytona.warm_pool.delete(pool.id) | ||
| print("Deleted warm pool") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) |
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,28 @@ | ||
| from daytona import Daytona | ||
|
|
||
|
|
||
| def main(): | ||
| daytona = Daytona() | ||
|
|
||
| # Create a warm pool that keeps ready-to-use sandboxes for an existing snapshot. | ||
| # `target` is optional and defaults to the organization default region. | ||
| pool = daytona.warm_pool.create("my-snapshot", pool=3) | ||
| print(f"Created warm pool {pool.id} for snapshot '{pool.snapshot}' in {pool.target}") | ||
|
|
||
| # List warm pools. current_size vs pool is the status check: current_size is the | ||
| # number of ready sandboxes; error_reason is set when the pool cannot be filled. | ||
| for p in daytona.warm_pool.list(): | ||
| status = f" (error: {p.error_reason})" if p.error_reason else "" | ||
| print(f"{p.snapshot} ({p.target}): {p.current_size}/{p.pool} ready{status}") | ||
|
|
||
| # Grow the pool. Setting pool to 0 drains it without deleting the pool. | ||
| updated = daytona.warm_pool.update(pool.id, pool=5) | ||
| print(f"Updated desired size to {updated.pool}") | ||
|
|
||
| # Cleanup | ||
| daytona.warm_pool.delete(pool.id) | ||
| print("Deleted warm pool") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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,25 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'daytona' | ||
|
|
||
| daytona = Daytona::Daytona.new | ||
|
|
||
| # Create a warm pool that keeps ready-to-use sandboxes for an existing snapshot. | ||
| # `target` is optional and defaults to the organization default region. | ||
| pool = daytona.warm_pool.create('my-snapshot', 3) | ||
| puts "Created warm pool #{pool.id} for snapshot '#{pool.snapshot}' in #{pool.target}" | ||
|
|
||
| # List warm pools. current_size vs pool is the status check: current_size is the | ||
| # number of ready sandboxes; error_reason is set when the pool cannot be filled. | ||
| daytona.warm_pool.list.each do |p| | ||
| status = p.error_reason ? " (error: #{p.error_reason})" : '' | ||
| puts "#{p.snapshot} (#{p.target}): #{p.current_size}/#{p.pool} ready#{status}" | ||
| end | ||
|
|
||
| # Grow the pool. Setting the size to 0 drains it without deleting the pool. | ||
| updated = daytona.warm_pool.update(pool.id, 5) | ||
| puts "Updated desired size to #{updated.pool}" | ||
|
|
||
| # Cleanup | ||
| daytona.warm_pool.delete(pool.id) | ||
| puts 'Deleted warm pool' |
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,28 @@ | ||
| import { Daytona } from '@daytona/sdk' | ||
|
|
||
| async function main() { | ||
| const daytona = new Daytona() | ||
|
|
||
| // Create a warm pool that keeps ready-to-use sandboxes for an existing snapshot. | ||
| // `target` is optional and defaults to the organization default region. | ||
| const pool = await daytona.warmPool.create({ snapshot: 'my-snapshot', pool: 3 }) | ||
| console.log(`Created warm pool ${pool.id} for snapshot '${pool.snapshot}' in ${pool.target}`) | ||
|
|
||
| // List warm pools. currentSize vs pool is the status check: currentSize is the | ||
| // number of ready sandboxes; errorReason is set when the pool cannot be filled. | ||
| const pools = await daytona.warmPool.list() | ||
| for (const p of pools) { | ||
| const status = p.errorReason ? ` (error: ${p.errorReason})` : '' | ||
| console.log(`${p.snapshot} (${p.target}): ${p.currentSize}/${p.pool} ready${status}`) | ||
| } | ||
|
|
||
| // Grow the pool. Setting pool to 0 drains it without deleting the pool. | ||
| const updated = await daytona.warmPool.update(pool.id, { pool: 5 }) | ||
| console.log(`Updated desired size to ${updated.pool}`) | ||
|
|
||
| // Cleanup | ||
| await daytona.warmPool.delete(pool.id) | ||
| console.log('Deleted warm pool') | ||
| } | ||
|
|
||
| main() |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Cleanup on line 28 is not guaranteed if a prior operation throws. Wrap the body in try/finally so delete still runs on failure — the Lifecycle example demonstrates this pattern.
Prompt for AI agents