Skip to content
Browse files

deprecate client rake and start in favor of rendezvous

  • Loading branch information...
1 parent ea8cf39 commit 2d6f4e69b6539906e93ac318560858cf2a8dbf8e @geemus geemus committed Aug 2, 2012
Showing with 75 additions and 68 deletions.
  1. +66 −65 lib/heroku/client.rb
  2. +9 −3 spec/heroku/client_spec.rb
View
131 lib/heroku/client.rb
@@ -341,75 +341,12 @@ def migrate_to_stack(app_name, stack)
put("/apps/#{app_name}/stack", stack, :accept => 'text/plain').to_s
end
- # :nocov:
-
- def add_ssl(app_name, pem, key)
- json_decode(post("/apps/#{app_name}/ssl", :pem => pem, :key => key).to_s)
- end
-
- def remove_ssl(app_name, domain)
- delete("/apps/#{app_name}/domains/#{domain}/ssl").to_s
- end
-
- def clear_ssl(app_name)
- delete("/apps/#{app_name}/ssl")
- end
-
- class AppCrashed < RuntimeError; end
-
- # Run a rake command on the Heroku app and return all output as
- # a string.
+ # Run a rake command on the Heroku app and return output as a string
def rake(app_name, cmd)
+ # deprecated by virtue of start deprecation 08/02/2012
start(app_name, "rake #{cmd}", :attached).to_s
end
- # support for console sessions
- class ConsoleSession
- def initialize(id, app, client)
- require 'rest_client'
- @id = id; @app = app; @client = client
- end
- def run(cmd)
- @client.run_console_command("/apps/#{@app}/consoles/#{@id}/command", cmd, "=> ")
- end
- end
-
- # Execute a one-off console command, or start a new console tty session if
- # cmd is nil.
- def console(app_name, cmd=nil)
- if block_given?
- id = post("/apps/#{app_name}/consoles").to_s
- yield ConsoleSession.new(id, app_name, self)
- delete("/apps/#{app_name}/consoles/#{id}").to_s
- else
- run_console_command("/apps/#{app_name}/console", cmd)
- end
- rescue RestClient::BadGateway => e
- raise(AppCrashed, <<-ERROR)
-Unable to attach to a dyno to open a console session.
-Your application may have crashed.
-Check the output of "heroku ps" and "heroku logs" for more information.
- ERROR
- end
-
- # internal method to run console commands formatting the output
- def run_console_command(url, command, prefix=nil)
- output = post(url, { :command => command }, :accept => "text/plain").to_s
- return output unless prefix
- if output.include?("\n")
- lines = output.split("\n")
- (lines[0..-2] << "#{prefix}#{lines.last}").join("\n")
- else
- prefix + output
- end
- rescue RestClient::RequestFailed => e
- if e.http_code == 422
- Heroku::Command.extract_error(e.http_body, :raw => true)
- else
- raise e
- end
- end
-
class Service
attr_accessor :attached
@@ -478,10 +415,74 @@ def to_s
# Run a service. If Responds to #each and yields output as it's received.
def start(app_name, command, attached=false)
+ deprecate # 08/02/2012
service = Service.new(self, app_name)
service.start(command, attached)
end
+ # :nocov:
+
+ def add_ssl(app_name, pem, key)
+ json_decode(post("/apps/#{app_name}/ssl", :pem => pem, :key => key).to_s)
+ end
+
+ def remove_ssl(app_name, domain)
+ delete("/apps/#{app_name}/domains/#{domain}/ssl").to_s
+ end
+
+ def clear_ssl(app_name)
+ delete("/apps/#{app_name}/ssl")
+ end
+
+ class AppCrashed < RuntimeError; end
+
+ # support for console sessions
+ class ConsoleSession
+ def initialize(id, app, client)
+ require 'rest_client'
+ @id = id; @app = app; @client = client
+ end
+ def run(cmd)
+ @client.run_console_command("/apps/#{@app}/consoles/#{@id}/command", cmd, "=> ")
+ end
+ end
+
+ # Execute a one-off console command, or start a new console tty session if
+ # cmd is nil.
+ def console(app_name, cmd=nil)
+ if block_given?
+ id = post("/apps/#{app_name}/consoles").to_s
+ yield ConsoleSession.new(id, app_name, self)
+ delete("/apps/#{app_name}/consoles/#{id}").to_s
+ else
+ run_console_command("/apps/#{app_name}/console", cmd)
+ end
+ rescue RestClient::BadGateway => e
+ raise(AppCrashed, <<-ERROR)
+Unable to attach to a dyno to open a console session.
+Your application may have crashed.
+Check the output of "heroku ps" and "heroku logs" for more information.
+ ERROR
+ end
+
+ # internal method to run console commands formatting the output
+ def run_console_command(url, command, prefix=nil)
+ output = post(url, { :command => command }, :accept => "text/plain").to_s
+ return output unless prefix
+ if output.include?("\n")
+ lines = output.split("\n")
+ (lines[0..-2] << "#{prefix}#{lines.last}").join("\n")
+ else
+ prefix + output
+ end
+ rescue RestClient::RequestFailed => e
+ if e.http_code == 422
+ Heroku::Command.extract_error(e.http_body, :raw => true)
+ else
+ raise e
+ end
+ end
+
def read_logs(app_name, options=[])
query = "&" + options.join("&") unless options.empty?
url = get("/apps/#{app_name}/logs?logplex=true#{query}").to_s
View
12 spec/heroku/client_spec.rb
@@ -103,7 +103,9 @@
it "rake(app_name, cmd) -> run a rake command on the app" do
stub_api_request(:post, "/apps/myapp/services").with(:body => "rake db:migrate").to_return(:body => "foo")
stub_api_request(:get, "/foo").to_return(:body => "output")
- @client.rake('myapp', 'db:migrate')
+ capture_stderr do # capture deprecation message
+ @client.rake('myapp', 'db:migrate')
+ end
end
it "console(app_name, cmd) -> run a console command on the app" do
@@ -205,15 +207,19 @@
e.stub!(:http_code).and_return(502)
e.stub!(:http_body).and_return('the crashlog')
@client.should_receive(:post).and_raise(e)
- lambda { @client.rake('myapp', '') }.should raise_error(Heroku::Client::AppCrashed)
+ capture_stderr do # capture deprecation message
+ lambda { @client.rake('myapp', '') }.should raise_error(Heroku::Client::AppCrashed)
+ end
end
it "rake passes other status codes (i.e., 500) as standard restclient exceptions" do
e = RestClient::RequestFailed.new
e.stub!(:http_code).and_return(500)
e.stub!(:http_body).and_return('not a crashlog')
@client.should_receive(:post).and_raise(e)
- lambda { @client.rake('myapp', '') }.should raise_error(RestClient::RequestFailed)
+ capture_stderr do # capture deprecation message
+ lambda { @client.rake('myapp', '') }.should raise_error(RestClient::RequestFailed)
+ end
end
describe "ps_scale" do

0 comments on commit 2d6f4e6

Please sign in to comment.
Something went wrong with that request. Please try again.