heroku / platform-api

Ruby HTTP client for the Heroku API
MIT License
214 stars 85 forks source link

Stop one off Dyno with custom Type #57

Open AaronCowan opened 7 years ago

AaronCowan commented 7 years ago

Potential Bug Start a one-off dyno with this command

heroku.dyno.create(heroku_app, {command: "while :; do echo 'hit ctrl-c'; sleep 1; done", type: "test"})

Heroku logs this:

app[api]: Starting process with command 'while :; do echo 'hit ctrl-c'; sleep 1; done' by user

But this Dyno is not killed with the command

heroku.dyno.restart(heroku_app, "test.1234") # assuming the Dyno name is test.1234 Returned is an empty hash {}

Stopping with heroku ps:stop test.1234 works

This does not occur if you do not specify the "type" during the create call. For example, you can kill a one-off Dyno that is named something like run.1234

geemus commented 7 years ago

Thanks for the detailed report. It looks like, underneath the covers there is special branching behavior for restart which is based on the type string (so if it is run, it does something different). Which I think is likely to explain the problem you are seeing.

The most direct way to avoid this, as you might imagine, is to simply omit the type so that it will be set to run (or explicitly set it that way).

Alternatively, there is a way in the API to explicitly initiate a stop, which would utilize POST /apps/{app-identifier}/dynos/{dyno-identifier}/actions/stop. This is documented in the API docs here, but for reasons that are not totally clear to me doesn't automatically get added to this client.

There may be worth further/deeper investigation, but for now hopefully that clears up your confusion and gives you some clearer workaround.

AaronCowan commented 7 years ago

@geemus Thanks for the response. I appreciate it.

glorkio commented 6 years ago

POST /apps/{app-identifier}/dynos/{dyno-identifier}/actions/stop will idle a dyno. How do I actually delete the dyno using the platform API (ie., the equivalent of "heroku ps:scale web=0")?

mikehale commented 6 years ago

@glorkio you update the formation. BTW a great way to explore what the CLI is doing is to use HEROKU_DEBUG=1, so HEROKU_DEBUG=1 heroku ps:scale web=0

glorkio commented 6 years ago

Thank you for your doubly helpful reply!