Class: Jatai::Commands::Up

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

Constant Summary collapse

POLL_INTERVAL =
5
PROVISION_TIMEOUT =
1200
DEPLOY_TIMEOUT =
1800
PROVISION_MAX_POLLS =
240
DEPLOY_MAX_POLLS =
360

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



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jatai/commands/up.rb', line 14

def execute(options = {})
  require_auth!
  config = project_config

  @app = find_or_create_app(config)
  slug = @app["slug"]

  if %w[active sleeping].include?(@app["status"])
    info("Iniciando deploy...")
  else
    info("Provisionando infraestrutura...")
    trigger_provision(slug) if %w[pending error].include?(@app["status"])
    unless wait_for_provisioning(@app["id"], slug)
      return
    end
    success("Infraestrutura provisionada!")
    info("Iniciando primeiro deploy...")
  end

  deploy = trigger_deploy(slug)
  info("       Na fila...")

  if wait_for_deploy_complete(slug, deploy["id"])
    subdomain = @app["subdomain"] || slug
    success("Deploy concluĂ­do! App disponĂ­vel em https://#{subdomain}.usebrasa.com.br")
  end
rescue Api::Client::ValidationError => e
  error("Erro ao criar app: #{e.message}")
rescue Api::Client::ApiError => e
  error("Erro: #{e.message}")
end