Class: EPC::Command::DeployCommand

Inherits:
BaseCommand show all
Defined in:
lib/epc/command/deploy_command.rb

Constant Summary collapse

SLEEP_TIME =
1
TICKER_TICKS =

Numerators are in secs

25/SLEEP_TIME
GIVEUP_TICKS =
120/SLEEP_TIME

Instance Attribute Summary

Attributes inherited from BaseCommand

#client, #klass_name, #object_id, #object_type, #options, #target_id, #target_type

Instance Method Summary collapse

Methods inherited from BaseCommand

#check_options, #context_params, #context_params=, #go, include_module, inherited, #initialize, required_options, #say_err

Methods included from PersistentAttributes

#auth_token, #caller_id, #target_url

Constructor Details

This class inherits a constructor from EPC::Command::BaseCommand

Instance Method Details

#execute(stage = nil) ⇒ Object

Raises:



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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/epc/command/deploy_command.rb', line 9

def execute(stage = nil)
  path = "."  
  path = File.expand_path(path)

  if  !( EPC::Config.is_solution_dir?(path) || EPC::Config.is_project_dir?(path)) && @options[:deployment_id].nil?
    say_err("This is not a solution directory.")
    return 1
  end

  if @options[:no_poll].present? && @options[:timeout].present?
    raise InputError, "You cannot specify both --nopoll and --timeout options at the same time"
  end

  @timeout = GIVEUP_TICKS

  solution_id, solution_name = infer_solution_context(nil, path)

  if @options[:deployment_id].nil?
    proceed = ask_yn("You are deploying the [#{solution_name}] solution. Correct? [Yn]: ")
    return 1 if proceed.upcase == 'N'
  end

  if @options[:use_local].present? && @options[:use_local]
    @options[:skip_build] = true
    result, versions = EPC::Command::PushCommand.new(client, @options).execute_internal
    return result if result != 0
    b_versions = (versions.map{|v| "#{v.keys.first}=#{v.values.first}"})
    result =  EPC::Command::BuildCommand.new(client, @options).execute(*b_versions)
    return result unless result.successful? || result == 0
  end

  deployment_id = @options[:deployment_id]

  deployment_id = create_deployment(solution_name, stage) if stage.present?
  deployment_id = create_deployment(solution_name, stage) if deployment_id.nil?

  raise FatalError, "Could not find/create deployment id." if deployment_id.nil? || deployment_id == -1

  parse_timeout_value

  begin
    say("Deploying #{deployment_id}")
    status, response = deploy(deployment_id)
    if @options[:no_poll].present?
      say("Request submitted")
      return status
    end
    say("Deploying - ")
    shown, deployment_status = poll_for_deployment_statuses(deployment_id)
    if shown
      display_statuses(deployment_status, response[:deployed_projects])
    end
  rescue Exception => ex
    say_err("Deploy failed [#{ex.to_s}].")
    return 1
  end
  return status
end