Class: ReplicateClient::Deployment
- Inherits:
-
Object
- Object
- ReplicateClient::Deployment
- Defined in:
- lib/replicate-client/deployment.rb
Constant Summary collapse
- INDEX_PATH =
"/deployments"
Instance Attribute Summary collapse
-
#current_release ⇒ Object
Attributes for deployment.
-
#name ⇒ Object
Attributes for deployment.
-
#owner ⇒ Object
Attributes for deployment.
Class Method Summary collapse
-
.auto_paging_each {|ReplicateClient::Deployment| ... } ⇒ void
List all deployments.
-
.build_path(owner:, name:) ⇒ String
Build the path for a specific deployment.
-
.create!(name:, model:, hardware:, min_instances:, max_instances:, version_id: nil) ⇒ ReplicateClient::Deployment
Create a new deployment.
-
.destroy!(owner:, name:) ⇒ void
Delete a deployment.
-
.find(full_name) ⇒ ReplicateClient::Deployment
Find a deployment by owner and name.
-
.find_by(owner:, name:) ⇒ ReplicateClient::Deployment?
Find a deployment by owner and name.
-
.find_by!(owner:, name:) ⇒ ReplicateClient::Deployment
Find a deployment by owner and name.
-
.parse_full_name(full_name) ⇒ Hash
Parse the full name for a deployment.
Instance Method Summary collapse
-
#create_prediction!(input, webhook_url: nil, webhook_events_filter: nil) ⇒ ReplicateClient::Prediction
Create prediction for the deployment.
-
#destroy! ⇒ void
Destroy the deployment.
-
#initialize(attributes) ⇒ ReplicateClient::Deployment
constructor
Initialize a new deployment instance.
-
#path ⇒ String
Build the path for the deployment.
-
#reload! ⇒ void
Reload the deployment.
-
#update!(hardware: nil, min_instances: nil, max_instances: nil, version: nil) ⇒ void
Update the deployment.
Constructor Details
#initialize(attributes) ⇒ ReplicateClient::Deployment
Initialize a new deployment instance.
138 139 140 |
# File 'lib/replicate-client/deployment.rb', line 138 def initialize(attributes) reset_attributes(attributes) end |
Instance Attribute Details
#current_release ⇒ Object
Attributes for deployment.
131 132 133 |
# File 'lib/replicate-client/deployment.rb', line 131 def current_release @current_release end |
#name ⇒ Object
Attributes for deployment.
131 132 133 |
# File 'lib/replicate-client/deployment.rb', line 131 def name @name end |
#owner ⇒ Object
Attributes for deployment.
131 132 133 |
# File 'lib/replicate-client/deployment.rb', line 131 def owner @owner end |
Class Method Details
.auto_paging_each {|ReplicateClient::Deployment| ... } ⇒ void
This method returns an undefined value.
List all deployments.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/replicate-client/deployment.rb', line 13 def auto_paging_each(&block) cursor = nil loop do url_params = cursor ? "?cursor=#{cursor}" : "" attributes = ReplicateClient.client.get("#{INDEX_PATH}#{url_params}") deployments = attributes["results"].map { |deployment| new(deployment) } deployments.each(&block) cursor = attributes["next"] ? URI.decode_www_form(URI.parse(attributes["next"]).query).to_h["cursor"] : nil break if cursor.nil? end end |
.build_path(owner:, name:) ⇒ String
Build the path for a specific deployment.
115 116 117 |
# File 'lib/replicate-client/deployment.rb', line 115 def build_path(owner:, name:) "#{INDEX_PATH}/#{owner}/#{name}" end |
.create!(name:, model:, hardware:, min_instances:, max_instances:, version_id: nil) ⇒ ReplicateClient::Deployment
Create a new deployment.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/replicate-client/deployment.rb', line 39 def create!(name:, model:, hardware:, min_instances:, max_instances:, version_id: nil) model_full_name = model.is_a?(Model) ? model.full_name : model hardware_sku = hardware.is_a?(Hardware) ? hardware.sku : hardware version = if version_id version_id elsif model.is_a?(Model) model.version_id else Model.find(model).latest_version.id end body = { name: name, model: model_full_name, version: version, hardware: hardware_sku, min_instances: min_instances, max_instances: max_instances } attributes = ReplicateClient.client.post(INDEX_PATH, body) new(attributes) end |
.destroy!(owner:, name:) ⇒ void
This method returns an undefined value.
Delete a deployment.
104 105 106 107 |
# File 'lib/replicate-client/deployment.rb', line 104 def destroy!(owner:, name:) path = build_path(owner: owner, name: name) ReplicateClient.client.delete(path) end |
.find(full_name) ⇒ ReplicateClient::Deployment
Find a deployment by owner and name.
68 69 70 71 72 |
# File 'lib/replicate-client/deployment.rb', line 68 def find(full_name) path = build_path(**parse_full_name(full_name)) attributes = ReplicateClient.client.get(path) new(attributes) end |
.find_by(owner:, name:) ⇒ ReplicateClient::Deployment?
Find a deployment by owner and name.
92 93 94 95 96 |
# File 'lib/replicate-client/deployment.rb', line 92 def find_by(owner:, name:) find_by!(owner: owner, name: name) rescue ReplicateClient::NotFoundError nil end |
.find_by!(owner:, name:) ⇒ ReplicateClient::Deployment
Find a deployment by owner and name.
80 81 82 83 84 |
# File 'lib/replicate-client/deployment.rb', line 80 def find_by!(owner:, name:) path = build_path(owner: owner, name: name) attributes = ReplicateClient.client.get(path) new(attributes) end |
.parse_full_name(full_name) ⇒ Hash
Parse the full name for a deployment.
124 125 126 127 |
# File 'lib/replicate-client/deployment.rb', line 124 def parse_full_name(full_name) parts = full_name.split("/") { owner: parts[0], name: parts[1] } end |
Instance Method Details
#create_prediction!(input, webhook_url: nil, webhook_events_filter: nil) ⇒ ReplicateClient::Prediction
Create prediction for the deployment.
193 194 195 196 197 198 199 200 |
# File 'lib/replicate-client/deployment.rb', line 193 def create_prediction!(input, webhook_url: nil, webhook_events_filter: nil) Prediction.create_for_deployment!( deployment: self, input: input, webhook_url: webhook_url, webhook_events_filter: webhook_events_filter ) end |
#destroy! ⇒ void
This method returns an undefined value.
Destroy the deployment.
145 146 147 |
# File 'lib/replicate-client/deployment.rb', line 145 def destroy! self.class.destroy!(owner: owner, name: name) end |
#path ⇒ String
Build the path for the deployment.
182 183 184 |
# File 'lib/replicate-client/deployment.rb', line 182 def path self.class.build_path(owner: owner, name: name) end |
#reload! ⇒ void
This method returns an undefined value.
Reload the deployment.
174 175 176 177 |
# File 'lib/replicate-client/deployment.rb', line 174 def reload! attributes = ReplicateClient.client.get(path) reset_attributes(attributes) end |
#update!(hardware: nil, min_instances: nil, max_instances: nil, version: nil) ⇒ void
This method returns an undefined value.
Update the deployment.
157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/replicate-client/deployment.rb', line 157 def update!(hardware: nil, min_instances: nil, max_instances: nil, version: nil) version_id = version.is_a?(Version) ? version.id : version path = build_path(owner: owner, name: name) body = { hardware: hardware, min_instances: min_instances, max_instances: max_instances, version: version_id }.compact attributes = ReplicateClient.client.patch(path, body) reset_attributes(attributes) end |