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
-
#client ⇒ ReplicateClient::Client
The client used to make API requests for this deployment.
-
#current_release ⇒ Object
Attributes for deployment.
-
#name ⇒ Object
Attributes for deployment.
-
#owner ⇒ Object
Attributes for deployment.
Class Method Summary collapse
-
.auto_paging_each(client: ReplicateClient.client) {|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, client: ReplicateClient.client) ⇒ ReplicateClient::Deployment
Create a new deployment.
-
.destroy!(owner:, name:, client: ReplicateClient.client) ⇒ void
Delete a deployment.
-
.find(full_name, client: ReplicateClient.client) ⇒ ReplicateClient::Deployment
Find a deployment by owner and name.
-
.find_by(owner:, name:, client: ReplicateClient.client) ⇒ ReplicateClient::Deployment?
Find a deployment by owner and name.
-
.find_by!(owner:, name:, client: ReplicateClient.client) ⇒ 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, client: ReplicateClient.client) ⇒ 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, client: ReplicateClient.client) ⇒ ReplicateClient::Deployment
Initialize a new deployment instance.
152 153 154 155 |
# File 'lib/replicate-client/deployment.rb', line 152 def initialize(attributes, client: ReplicateClient.client) @client = client reset_attributes(attributes) end |
Instance Attribute Details
#client ⇒ ReplicateClient::Client
The client used to make API requests for this deployment.
144 145 146 |
# File 'lib/replicate-client/deployment.rb', line 144 def client @client end |
#current_release ⇒ Object
Attributes for deployment.
139 140 141 |
# File 'lib/replicate-client/deployment.rb', line 139 def current_release @current_release end |
#name ⇒ Object
Attributes for deployment.
139 140 141 |
# File 'lib/replicate-client/deployment.rb', line 139 def name @name end |
#owner ⇒ Object
Attributes for deployment.
139 140 141 |
# File 'lib/replicate-client/deployment.rb', line 139 def owner @owner end |
Class Method Details
.auto_paging_each(client: ReplicateClient.client) {|ReplicateClient::Deployment| ... } ⇒ void
This method returns an undefined value.
List all deployments.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/replicate-client/deployment.rb', line 15 def auto_paging_each(client: ReplicateClient.client, &block) cursor = nil loop do url_params = cursor ? "?cursor=#{cursor}" : "" attributes = client.get("#{INDEX_PATH}#{url_params}") deployments = attributes["results"].map { |deployment| new(deployment, client: client) } 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.
123 124 125 |
# File 'lib/replicate-client/deployment.rb', line 123 def build_path(owner:, name:) "#{INDEX_PATH}/#{owner}/#{name}" end |
.create!(name:, model:, hardware:, min_instances:, max_instances:, version_id: nil, client: ReplicateClient.client) ⇒ ReplicateClient::Deployment
Create a new deployment.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/replicate-client/deployment.rb', line 42 def create!(name:, model:, hardware:, min_instances:, max_instances:, version_id: nil, client: ReplicateClient.client) 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, client: client).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 = client.post(INDEX_PATH, body) new(attributes, client: client) end |
.destroy!(owner:, name:, client: ReplicateClient.client) ⇒ void
This method returns an undefined value.
Delete a deployment.
112 113 114 115 |
# File 'lib/replicate-client/deployment.rb', line 112 def destroy!(owner:, name:, client: ReplicateClient.client) path = build_path(owner: owner, name: name) client.delete(path) end |
.find(full_name, client: ReplicateClient.client) ⇒ ReplicateClient::Deployment
Find a deployment by owner and name.
73 74 75 76 77 |
# File 'lib/replicate-client/deployment.rb', line 73 def find(full_name, client: ReplicateClient.client) path = build_path(**parse_full_name(full_name)) attributes = client.get(path) new(attributes, client: client) end |
.find_by(owner:, name:, client: ReplicateClient.client) ⇒ ReplicateClient::Deployment?
Find a deployment by owner and name.
99 100 101 102 103 |
# File 'lib/replicate-client/deployment.rb', line 99 def find_by(owner:, name:, client: ReplicateClient.client) find_by!(owner: owner, name: name, client: client) rescue ReplicateClient::NotFoundError nil end |
.find_by!(owner:, name:, client: ReplicateClient.client) ⇒ ReplicateClient::Deployment
Find a deployment by owner and name.
86 87 88 89 90 |
# File 'lib/replicate-client/deployment.rb', line 86 def find_by!(owner:, name:, client: ReplicateClient.client) path = build_path(owner: owner, name: name) attributes = client.get(path) new(attributes, client: client) end |
.parse_full_name(full_name) ⇒ Hash
Parse the full name for a deployment.
132 133 134 135 |
# File 'lib/replicate-client/deployment.rb', line 132 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.
208 209 210 211 212 213 214 215 216 |
# File 'lib/replicate-client/deployment.rb', line 208 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, client: @client ) end |
#destroy! ⇒ void
This method returns an undefined value.
Destroy the deployment.
160 161 162 |
# File 'lib/replicate-client/deployment.rb', line 160 def destroy! self.class.destroy!(owner: owner, name: name, client: @client) end |
#path ⇒ String
Build the path for the deployment.
197 198 199 |
# File 'lib/replicate-client/deployment.rb', line 197 def path self.class.build_path(owner: owner, name: name) end |
#reload! ⇒ void
This method returns an undefined value.
Reload the deployment.
189 190 191 192 |
# File 'lib/replicate-client/deployment.rb', line 189 def reload! attributes = @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.
172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/replicate-client/deployment.rb', line 172 def update!(hardware: nil, min_instances: nil, max_instances: nil, version: nil) version_id = version.is_a?(ReplicateClient::Model::Version) ? version.id : version path = self.class.build_path(owner: owner, name: name) body = { hardware: hardware, min_instances: min_instances, max_instances: max_instances, version: version_id }.compact attributes = @client.patch(path, body) reset_attributes(attributes) end |