Class: Daytona::Daytona
- Inherits:
-
Object
- Object
- Daytona::Daytona
- Includes:
- Instrumentation
- Defined in:
- lib/daytona/daytona.rb
Instance Attribute Summary collapse
- #api_client ⇒ DaytonaApiClient readonly
- #config ⇒ Daytona::Config readonly
- #object_storage_api ⇒ DaytonaApiClient::ObjectStorageApi readonly
- #sandbox_api ⇒ DaytonaApiClient::SandboxApi readonly
- #secret ⇒ Daytona::SecretService readonly
- #snapshot ⇒ Daytona::SnapshotService readonly
- #snapshots_api ⇒ DaytonaApiClient::SnapshotsApi readonly
- #volume ⇒ Daytona::VolumeService readonly
- #warm_pool ⇒ Daytona::WarmPoolService readonly
Instance Method Summary collapse
-
#close ⇒ void
Shuts down OTel providers, flushing any pending telemetry data.
-
#create(params = nil, on_snapshot_create_logs: nil) ⇒ Daytona::Sandbox
Creates a sandbox with the specified parameters.
-
#delete(sandbox, wait: false) ⇒ void
Deletes a Sandbox.
-
#get(id) ⇒ Daytona::Sandbox
Gets a Sandbox by its ID.
-
#initialize(config = Config.new) ⇒ Daytona
constructor
A new instance of Daytona.
-
#list(query = nil) ⇒ Enumerator<Daytona::Sandbox>
Iterates over Sandboxes matching the given query.
-
#start(sandbox, timeout = Sandbox::DEFAULT_TIMEOUT) ⇒ void
Starts a Sandbox and waits for it to be ready.
-
#stop(sandbox, timeout = Sandbox::DEFAULT_TIMEOUT) ⇒ void
Stops a Sandbox and waits for it to be stopped.
Methods included from Instrumentation
Constructor Details
#initialize(config = Config.new) ⇒ Daytona
Returns a new instance of Daytona.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/daytona/daytona.rb', line 41 def initialize(config = Config.new) @config = config ensure_access_token_defined otel_enabled = config.otel_enabled || config._experimental&.dig('otel_enabled') || config.read_env('DAYTONA_OTEL_ENABLED') == 'true' || config.read_env('DAYTONA_EXPERIMENTAL_OTEL_ENABLED') == 'true' @otel_state = (::Daytona.init_otel(Sdk::VERSION) if otel_enabled) @api_client = build_api_client @sandbox_api = DaytonaApiClient::SandboxApi.new(api_client) @config_api = DaytonaApiClient::ConfigApi.new(api_client) @analytics_api_url = nil @analytics_api_url_fetched = false @analytics_api_url_mutex = Mutex.new @volume = VolumeService.new(DaytonaApiClient::VolumesApi.new(api_client), otel_state:) @secret = SecretService.new(DaytonaApiClient::SecretApi.new(api_client), otel_state:) @warm_pool = WarmPoolService.new(DaytonaApiClient::WarmPoolsApi.new(api_client), otel_state:) @object_storage_api = DaytonaApiClient::ObjectStorageApi.new(api_client) @snapshots_api = DaytonaApiClient::SnapshotsApi.new(api_client) @snapshot = SnapshotService.new( snapshots_api:, object_storage_api:, default_region_id: config.target, otel_state: ) token = config.api_key || config.jwt_token if config.use_deprecated_polling warn( '[DEPRECATION] Polling-only mode (use_deprecated_polling / DAYTONA_USE_DEPRECATED_POLLING) ' \ 'is deprecated and will be removed in a future release.', uplevel: 1 ) else @event_dispatcher = EventDispatcher.new( api_url: config.api_url, token: token, organization_id: config.organization_id, source: SOURCE_RUBY, sdk_version: Sdk::VERSION ) @event_dispatcher.ensure_connected end @subscription_manager = EventSubscriptionManager.new(@event_dispatcher) end |
Instance Attribute Details
#api_client ⇒ DaytonaApiClient (readonly)
17 18 19 |
# File 'lib/daytona/daytona.rb', line 17 def api_client @api_client end |
#config ⇒ Daytona::Config (readonly)
14 15 16 |
# File 'lib/daytona/daytona.rb', line 14 def config @config end |
#object_storage_api ⇒ DaytonaApiClient::ObjectStorageApi (readonly)
32 33 34 |
# File 'lib/daytona/daytona.rb', line 32 def object_storage_api @object_storage_api end |
#sandbox_api ⇒ DaytonaApiClient::SandboxApi (readonly)
20 21 22 |
# File 'lib/daytona/daytona.rb', line 20 def sandbox_api @sandbox_api end |
#secret ⇒ Daytona::SecretService (readonly)
26 27 28 |
# File 'lib/daytona/daytona.rb', line 26 def secret @secret end |
#snapshot ⇒ Daytona::SnapshotService (readonly)
38 39 40 |
# File 'lib/daytona/daytona.rb', line 38 def snapshot @snapshot end |
#snapshots_api ⇒ DaytonaApiClient::SnapshotsApi (readonly)
35 36 37 |
# File 'lib/daytona/daytona.rb', line 35 def snapshots_api @snapshots_api end |
#volume ⇒ Daytona::VolumeService (readonly)
23 24 25 |
# File 'lib/daytona/daytona.rb', line 23 def volume @volume end |
#warm_pool ⇒ Daytona::WarmPoolService (readonly)
29 30 31 |
# File 'lib/daytona/daytona.rb', line 29 def warm_pool @warm_pool end |
Instance Method Details
#close ⇒ void
This method returns an undefined value.
Shuts down OTel providers, flushing any pending telemetry data.
93 94 95 96 97 98 99 100 |
# File 'lib/daytona/daytona.rb', line 93 def close @subscription_manager&.shutdown @subscription_manager = nil @event_dispatcher&.disconnect @event_dispatcher = nil ::Daytona.shutdown_otel(@otel_state) @otel_state = nil end |
#create(params = nil, on_snapshot_create_logs: nil) ⇒ Daytona::Sandbox
Creates a sandbox with the specified parameters
108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/daytona/daytona.rb', line 108 def create(params = nil, on_snapshot_create_logs: nil) if params.nil? params = CreateSandboxFromSnapshotParams.new(language: CodeLanguage::PYTHON) elsif params.language.nil? params.language = CodeLanguage::PYTHON end unless CodeLanguage::ALL.include?(params.language.to_s.to_sym) raise ArgumentError, "Invalid #{CODE_TOOLBOX_LANGUAGE_LABEL}: #{params.language}. Supported languages: #{CodeLanguage::ALL.join(', ')}" end _create(params, on_snapshot_create_logs:) end |
#delete(sandbox, wait: false) ⇒ void
This method returns an undefined value.
Deletes a Sandbox.
128 |
# File 'lib/daytona/daytona.rb', line 128 def delete(sandbox, wait: false) = sandbox.delete(wait:) |
#get(id) ⇒ Daytona::Sandbox
Gets a Sandbox by its ID.
135 136 137 138 139 140 |
# File 'lib/daytona/daytona.rb', line 135 def get(id) sandbox_dto = sandbox_api.get_sandbox(id) to_sandbox(sandbox_dto:) rescue *Sdk::API_ERROR_CLASSES => e raise Sdk.wrap_error(e, "Failed to get sandbox #{id}") end |
#list(query = nil) ⇒ Enumerator<Daytona::Sandbox>
Iterates over Sandboxes matching the given query.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/daytona/daytona.rb', line 152 def list(query = nil) q = query || ListSandboxesQuery.new Enumerator.new do |yielder| cursor = nil first_page = true while first_page || cursor first_page = false response = fetch_sandbox_page(q, cursor) response.items.each do |sandbox_dto| yielder << to_sandbox(sandbox_dto: sandbox_dto) end cursor = response.next_cursor break if cursor.nil? || (cursor.respond_to?(:empty?) && cursor.empty?) end end end |
#start(sandbox, timeout = Sandbox::DEFAULT_TIMEOUT) ⇒ void
This method returns an undefined value.
Starts a Sandbox and waits for it to be ready.
175 |
# File 'lib/daytona/daytona.rb', line 175 def start(sandbox, timeout = Sandbox::DEFAULT_TIMEOUT) = sandbox.start(timeout) |
#stop(sandbox, timeout = Sandbox::DEFAULT_TIMEOUT) ⇒ void
This method returns an undefined value.
Stops a Sandbox and waits for it to be stopped.
182 |
# File 'lib/daytona/daytona.rb', line 182 def stop(sandbox, timeout = Sandbox::DEFAULT_TIMEOUT) = sandbox.stop(timeout) |