Class: OpenSandbox::Pools

Inherits:
Object
  • Object
show all
Defined in:
lib/open_sandbox/pools.rb

Overview

Manages pre-warmed resource pools for reduced sandbox cold-start latency.

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ Pools

Returns a new instance of Pools.



6
7
8
# File 'lib/open_sandbox/pools.rb', line 6

def initialize(http)
  @http = http
end

Instance Method Details

#create(name:, template:, capacity_spec:) ⇒ Pool

Create a new pre-warmed pool.

Parameters:

  • name (String)

    unique pool name (lowercase alphanumeric + hyphens)

  • template (Hash)

    Kubernetes PodTemplateSpec

  • capacity_spec (PoolCapacitySpec, Hash)

    capacity configuration

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/open_sandbox/pools.rb', line 33

def create(name:, template:, capacity_spec:)
  spec = capacity_spec.is_a?(PoolCapacitySpec) ? capacity_spec.to_api_hash : capacity_spec.transform_keys(&:to_s).then do |h|
    {
      "bufferMax" => h["buffer_max"] || h["bufferMax"],
      "bufferMin" => h["buffer_min"] || h["bufferMin"],
      "poolMax"   => h["pool_max"]   || h["poolMax"],
      "poolMin"   => h["pool_min"]   || h["poolMin"]
    }
  end

  body = { "name" => name.to_s, "template" => template, "capacitySpec" => spec }
  Pool.from_hash(@http.post("/v1/pools", body: body))
end

#delete(pool_name) ⇒ nil

Delete a pool.

Parameters:

  • pool_name (String)

Returns:

  • (nil)


62
63
64
# File 'lib/open_sandbox/pools.rb', line 62

def delete(pool_name)
  @http.delete("/v1/pools/#{pool_name}")
end

#get(pool_name) ⇒ Pool

Get a pool by name.

Parameters:

  • pool_name (String)

Returns:

Raises:



23
24
25
# File 'lib/open_sandbox/pools.rb', line 23

def get(pool_name)
  Pool.from_hash(@http.get("/v1/pools/#{pool_name}"))
end

#listArray<Pool>

List all pools.

Returns:



13
14
15
16
# File 'lib/open_sandbox/pools.rb', line 13

def list
  data = @http.get("/v1/pools")
  (data["items"] || []).map { Pool.from_hash(_1) }
end

#update(pool_name, capacity_spec:) ⇒ Pool

Update pool capacity configuration.

Parameters:

Returns:



52
53
54
55
56
# File 'lib/open_sandbox/pools.rb', line 52

def update(pool_name, capacity_spec:)
  spec = capacity_spec.is_a?(PoolCapacitySpec) ? capacity_spec.to_api_hash : capacity_spec
  body = { "capacitySpec" => spec }
  Pool.from_hash(@http.put("/v1/pools/#{pool_name}", body: body))
end