Class: OpenSandbox::Pools
- Inherits:
-
Object
- Object
- OpenSandbox::Pools
- Defined in:
- lib/open_sandbox/pools.rb
Overview
Manages pre-warmed resource pools for reduced sandbox cold-start latency.
Instance Method Summary collapse
-
#create(name:, template:, capacity_spec:) ⇒ Pool
Create a new pre-warmed pool.
-
#delete(pool_name) ⇒ nil
Delete a pool.
-
#get(pool_name) ⇒ Pool
Get a pool by name.
-
#initialize(http) ⇒ Pools
constructor
A new instance of Pools.
-
#list ⇒ Array<Pool>
List all pools.
-
#update(pool_name, capacity_spec:) ⇒ Pool
Update pool capacity configuration.
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.
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.
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.
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 |
#list ⇒ Array<Pool>
List all pools.
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.
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 |