rohitpaulk rohitpaulk - 8 months ago 203
Ruby Question

How do I access the exit code of a heroku one-off dyno?

I'm using heroku's platform API + the rendezvous client to execute a command and retrieve it's output + exit code.

def run_command(heroku_client, app_name, command)
dyno = heroku_client.dyno.create(app_name, command: command, attach: true)

rendezvous_url = dyno["attach_url"]

rz = Rendezvous.new({
input:StringIO.new,
output:StringIO.new,
url: rendezvous_url
})

rz.start # Blocks until the command completes

rz.output.rewind
rz.output.readlines.join
end


I can fetch the output just fine, as shown above. I can't find a way to access the exit code though. I tried fetching
dyno.info
from the API after the process has exited, but I get a
404
.

Answer Source

Heroku doesn't support retrieving exit codes from a one-off dyno. One way to achieve this would be to use my_command; echo $? and then parse out the exit code manually. This gem has a plugin that does that.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download