Class: Modal::App
- Inherits:
-
Object
- Object
- Modal::App
- Defined in:
- lib/modal/app.rb
Instance Attribute Summary collapse
-
#app_id ⇒ Object
readonly
Returns the value of attribute app_id.
Class Method Summary collapse
Instance Method Summary collapse
- #create_sandbox(image, options = {}) ⇒ Object
- #image_from_aws_ecr(tag, secret) ⇒ Object
- #image_from_registry(tag) ⇒ Object
-
#initialize(app_id) ⇒ App
constructor
A new instance of App.
Constructor Details
#initialize(app_id) ⇒ App
Returns a new instance of App.
5 6 7 |
# File 'lib/modal/app.rb', line 5 def initialize(app_id) @app_id = app_id end |
Instance Attribute Details
#app_id ⇒ Object (readonly)
Returns the value of attribute app_id.
3 4 5 |
# File 'lib/modal/app.rb', line 3 def app_id @app_id end |
Class Method Details
.lookup(name, options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/modal/app.rb', line 9 def self.lookup(name, = {}) create_if_missing = [:create_if_missing] || false environment = [:environment] request = Modal::Client::AppGetOrCreateRequest.new( app_name: name, environment_name: Config.environment_name(environment), object_creation_type: create_if_missing ? Modal::Client::ObjectCreationType::OBJECT_CREATION_TYPE_CREATE_IF_MISSING : Modal::Client::ObjectCreationType::OBJECT_CREATION_TYPE_UNSPECIFIED ) resp = Modal.client.call(:app_get_or_create, request) new(resp.app_id) end |
Instance Method Details
#create_sandbox(image, options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/modal/app.rb', line 23 def create_sandbox(image, = {}) timeout_secs = [:timeout] ? [:timeout] / 1000 : 600 cpu_milli = ([:cpu] || 0.125) * 1000 memory_mb = [:memory] || 128 command = [:command] || ["sleep", "48h"] request = Modal::Client::SandboxCreateRequest.new( app_id: @app_id, definition: Modal::Client::Sandbox.new( entrypoint_args: command, image_id: image.image_id, timeout_secs: timeout_secs, network_access: Modal::Client::NetworkAccess.new( network_access_type: Modal::Client::NetworkAccess::NetworkAccessType::OPEN ), resources: Modal::Client::Resources.new( milli_cpu: cpu_milli.round, memory_mb: memory_mb.round ) ) ) create_resp = Modal.client.call(:sandbox_create, request) Sandbox.new(create_resp.sandbox_id) end |
#image_from_aws_ecr(tag, secret) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/modal/app.rb', line 53 def image_from_aws_ecr(tag, secret) unless secret.is_a?(Secret) raise TypeError, "secret must be a reference to an existing Secret, e.g. `Secret.from_name('my_secret')`" end image_registry_config = Modal::Client::ImageRegistryConfig.new( registry_auth_type: Modal::Client::RegistryAuthType::REGISTRY_AUTH_TYPE_AWS, secret_id: secret.secret_id ) Image.from_registry_internal(@app_id, tag, image_registry_config) end |
#image_from_registry(tag) ⇒ Object
49 50 51 |
# File 'lib/modal/app.rb', line 49 def image_from_registry(tag) Image.from_registry_internal(@app_id, tag) end |