Class: VMC::App::Start

Inherits:
Base
  • Object
show all
Defined in:
lib/vmc/cli/app/start.rb

Constant Summary collapse

APP_CHECK_LIMIT =
60

Instance Method Summary collapse

Methods inherited from Base

#app_status, #human_mb, #human_size, #megabytes, #memory_choices, #state_color

Methods inherited from CLI

#check_logged_in, #check_target, #client, client, client=, #client_target, #color_enabled?, #default_action, #ensure_config_dir, #err, #execute, #fail, #force?, #invalidate_client, #log_error, #name_list, #no_v2, #one_of, #precondition, #quiet?, #remove_target_info, #sane_target_url, #save_target_info, #save_targets, #set_target, #table, #target_file, #target_info, #targets_info, #tokens_file, #user_colors, #v2?, #verbose?

Methods included from Spacing

#indented, #justify, #line, #lines, #quiet?, #spaced, #start_line, #tabular, #text_width, #trim_escapes

Methods included from Interactive

#ask, #handler, #input_state, #list_choices, #prompt, #show_default

Instance Method Details

#check_application(app) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/vmc/cli/app/start.rb', line 73

def check_application(app)
  with_progress("Checking #{c(app.name, :name)}") do |s|
    if app.debug_mode == "suspend"
      s.skip do
        line "Application is in suspended debugging mode."
        line "It will wait for you to attach to it before starting."
      end
    end

    seconds = 0
    until app.healthy?
      sleep 1
      seconds += 1
      if seconds == APP_CHECK_LIMIT
        s.give_up do
          err "Application failed to start."
          # TODO: print logs
        end
      end
    end
  end
end

#startObject



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
# File 'lib/vmc/cli/app/start.rb', line 16

def start
  apps = input[:all] ? client.apps : input[:apps]
  fail "No applications given." if apps.empty?

  spaced(apps) do |app|
    app = filter(:start_app, app)

    switch_mode(app, input[:debug_mode])

    with_progress("Starting #{c(app.name, :name)}") do |s|
      if app.started?
        s.skip do
          err "Already started."
        end
      end

      app.start!
    end

    check_application(app)

    if app.debug_mode && !quiet?
      line
      invoke :instances, :app => app
    end
  end
end

#switch_mode(app, mode) ⇒ Object

set app debug mode, ensuring it’s valid, and shutting it down



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/vmc/cli/app/start.rb', line 45

def switch_mode(app, mode)
  mode = nil if mode == "none"
  mode = "run" if mode == "debug_mode" # no value given

  return false if app.debug_mode == mode

  if mode.nil?
    with_progress("Removing debug mode") do
      app.debug_mode = nil
      app.stop! if app.started?
    end

    return true
  end

  with_progress("Switching mode to #{c(mode, :name)}") do |s|
    runtime = client.runtimes.find { |r| r.name == app.runtime.name }
    modes = runtime.debug_modes

    if modes.include?(mode)
      app.debug_mode = mode
      app.stop! if app.started?
    else
      fail "Unknown mode '#{mode}'; available: #{modes.join ", "}"
    end
  end
end