Class: Jatai::Commands::Scale

Inherits:
Base
  • Object
show all
Defined in:
lib/jatai/commands/scale.rb

Instance Method Summary collapse

Methods inherited from Base

#api, #app_slug, #error, #info, #pastel, #project_config, #require_auth!, #success

Instance Method Details

#execute(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/jatai/commands/scale.rb', line 7

def execute(options = {})
  require_auth!
  slug = app_slug

  body = {}
  body[:replicas] = options["replicas"].to_i if options["replicas"]
  body[:preset] = options["preset"] if options["preset"]

  if body.empty?
    error("Informe ao menos --replicas ou --preset. Ex: jatai scale --replicas 3")
    return
  end

  estimate = api.post("/api/v1/apps/#{slug}/scale/estimate", body: body)
  info("Preset: #{estimate["preset"]}")
  info("Réplicas: #{estimate["replicas"]}") if estimate["replicas"]
  info("CPU: #{estimate["cpu_limit"]}  |  RAM: #{estimate["memory_limit"]}") if estimate["cpu_limit"]
  info("Custo estimado: R$ #{estimate["monthly_cost"]}/mês")

  prompt = TTY::Prompt.new
  unless prompt.yes?("Confirmar escalonamento?")
    info("Escalonamento cancelado.")
    return
  end

  api.put("/api/v1/apps/#{slug}/scale", body: body)
  success("Escalonamento aplicado com sucesso!")
rescue Api::Client::ApiError => e
  error("Erro: #{e.message}")
end