Class: Heroku::Command::Ps
Overview
manage dynos (dynos, workers)
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#dynos ⇒ Object
ps:dynos [QTY].
-
#index ⇒ Object
ps.
-
#resize ⇒ Object
ps:resize DYNO1=1X|2X [DYNO2=1X|2X …].
-
#restart ⇒ Object
ps:restart [DYNO].
-
#scale ⇒ Object
ps:scale DYNO1=AMOUNT1 [DYNO2=AMOUNT2 …].
-
#stop ⇒ Object
ps:stop DYNOS.
-
#workers ⇒ Object
ps:workers [QTY].
Methods inherited from Base
#api, #app, #heroku, #initialize, namespace
Methods included from Helpers
#action, #ask, #confirm, #confirm_billing, #confirm_command, #create_git_remote, #deprecate, #display, #display_header, #display_object, #display_row, #display_table, #error, error_with_failure, error_with_failure=, extended, extended_into, #fail, #format_bytes, #format_date, #format_error, #format_with_bang, #get_terminal_environment, #git, #has_git?, #home_directory, #host_name, #hprint, #hputs, included, included_into, #json_decode, #json_encode, #launchy, #line_formatter, #longest, #output_with_bang, #quantify, #redisplay, #retry_on_exception, #run_command, #running_on_a_mac?, #running_on_windows?, #set_buffer, #shell, #spinner, #status, #string_distance, #styled_array, #styled_error, #styled_hash, #styled_header, #suggestion, #time_ago, #truncate, #with_tty
Constructor Details
This class inherits a constructor from Heroku::Command::Base
Instance Method Details
#dynos ⇒ Object
ps:dynos [QTY]
DEPRECATED: use ‘pogo ps:scale dynos=N`
scale to QTY web processes
if QTY is not specified, display the number of web processes currently running
Example:
$ pogo ps:dynos 3 Scaling dynos… done, now running 3
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/heroku/command/ps.rb', line 20 def dynos # deprecation notice added to v2.21.3 on 03/16/12 display("~ `pogo ps:dynos QTY` has been deprecated and replaced with `pogo ps:scale dynos=QTY`") dynos = shift_argument validate_arguments! if dynos action("Scaling dynos") do new_dynos = api.put_dynos(app, dynos).body["dynos"] status("now running #{new_dynos}") end else app_data = api.get_app(app).body if app_data["stack"] == "cedar" raise(Heroku::Command::CommandFailed, "For Cedar apps, use `pogo ps`") else display("#{app} is running #{quantify("dyno", app_data["dynos"])}") end end end |
#index ⇒ Object
ps
list dynos for an app
Example:
$ pogo ps
run: one-off dyno
run.1: up for 5m: ‘bash`
web: ‘bundle exec thin start -p $PORT`
web.1: created for 30s
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/heroku/command/ps.rb', line 94 def index validate_arguments! processes = api.get_ps(app).body processes_by_command = Hash.new {|hash,key| hash[key] = []} processes.each do |process| name = process["process"].split(".").first elapsed = time_ago(Time.now - process['elapsed']) size = process.fetch("size", 1) if name == "run" key = "run: one-off processes" item = "%s (%sX): %s %s: `%s`" % [ process["process"], size, process["state"], elapsed, process["command"] ] else key = "#{name} (#{size}X): `#{process["command"]}`" item = "%s: %s %s" % [ process["process"], process["state"], elapsed ] end processes_by_command[key] << item end extract_run_id = /\.(\d+).*:/ processes_by_command.keys.each do |key| processes_by_command[key] = processes_by_command[key].sort do |x,y| x.match(extract_run_id).captures.first.to_i <=> y.match(extract_run_id).captures.first.to_i end end processes_by_command.keys.sort.each do |key| styled_header(key) styled_array(processes_by_command[key], :sort => false) end end |
#resize ⇒ Object
ps:resize DYNO1=1X|2X [DYNO2=1X|2X …]
resize dynos to the given size
Example:
$ pogo ps:resize web=2X worker=1X Resizing and restarting the specified dynos… done web dynos now 2X ($0.10/dyno-hour) worker dynos now 1X ($0.05/dyno-hour)
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/heroku/command/ps.rb', line 246 def resize app changes = {} args.each do |arg| if arg =~ /^([a-zA-Z0-9_]+)=(\d+)([xX]?)$/ changes[$1] = { "size" => $2.to_i } end end if changes.empty? = [ "Usage: pogo ps:resize DYNO1=1X|2X [DYNO2=1X|2X ...]", "Must specify DYNO and SIZE to resize." ] error(.join("\n")) end action("Resizing and restarting the specified dynos") do api.request( :expects => 200, :method => :put, :path => "/apps/#{app}/formation", :body => json_encode(changes) ) end changes.each do |type, | size = ["size"] price = sprintf("%.2f", 0.05 * size) display "#{type} dynos now #{size}X ($#{price}/dyno-hour)" end end |
#restart ⇒ Object
ps:restart [DYNO]
restart an app dyno
if DYNO is not specified, restarts all dynos on the app
Examples:
$ pogo ps:restart web.1 Restarting web.1 dyno… done
$ pogo ps:restart web Restarting web dyno… done
$ pogo ps:restart Restarting dynos… done
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/heroku/command/ps.rb', line 145 def restart dyno = shift_argument validate_arguments! , = case dyno when NilClass ["Restarting dynos", {}] when /.+\..+/ ps = args.first ["Restarting #{ps} dyno", { :ps => ps }] else type = args.first ["Restarting #{type} dynos", { :type => type }] end action() do api.post_ps_restart(app, ) end end |
#scale ⇒ Object
ps:scale DYNO1=AMOUNT1 [DYNO2=AMOUNT2 …]
scale dynos by the given amount
Examples:
$ pogo ps:scale web=3 worker+1 Scaling web dynos… done, now running 3 Scaling worker dynos… done, now running 1
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/heroku/command/ps.rb', line 177 def scale changes = {} args.each do |arg| if arg =~ /^([a-zA-Z0-9_]+)([=+-]\d+)$/ changes[$1] = $2 end end if changes.empty? error("Usage: pogo ps:scale DYNO1=AMOUNT1 [DYNO2=AMOUNT2 ...]\nMust specify DYNO and AMOUNT to scale.") end changes.keys.sort.each do |dyno| amount = changes[dyno] action("Scaling #{dyno} dynos") do amount.gsub!("=", "") new_qty = api.post_ps_scale(app, dyno, amount).body status("now running #{new_qty}") end end end |
#stop ⇒ Object
ps:stop DYNOS
stop an app dyno
Examples:
$ pogo stop run.3 Stopping run.3 dyno… done
$ pogo stop run Stopping run dynos… done
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/heroku/command/ps.rb', line 213 def stop dyno = shift_argument validate_arguments! , = case dyno when NilClass error("Usage: pogo ps:stop DYNO\nMust specify DYNO to stop.") when /.+\..+/ ps = args.first ["Stopping #{ps} dyno", { :ps => ps }] else type = args.first ["Stopping #{type} dynos", { :type => type }] end action() do api.post_ps_stop(app, ) end end |
#workers ⇒ Object
ps:workers [QTY]
DEPRECATED: use ‘pogo ps:scale workers=N`
scale to QTY background processes
if QTY is not specified, display the number of background processes currently running
Example:
$ pogo ps:dynos 3 Scaling workers… done, now running 3
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/heroku/command/ps.rb', line 57 def workers # deprecation notice added to v2.21.3 on 03/16/12 display("~ `pogo ps:workers QTY` has been deprecated and replaced with `pogo ps:scale workers=QTY`") workers = shift_argument validate_arguments! if workers action("Scaling workers") do new_workers = api.put_workers(app, workers).body["workers"] status("now running #{new_workers}") end else app_data = api.get_app(app).body if app_data["stack"] == "cedar" raise(Heroku::Command::CommandFailed, "For Cedar apps, use `pogo ps`") else display("#{app} is running #{quantify("worker", app_data["workers"])}") end end end |