Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running ‘heroku run:detached’ programmatically. How exactly?

Tags:

heroku

I've tried googling and stackoverflowing this and all I get is links back to the API reference or examples of scaling dynos, which is not what I want.

heroku run:detached is great as it just spins up a dyno with your app, runs whatever you want, then spins down the dyno.

How do I achieve the exact same things but using the Heroku Platform API?

I've seen people mention you have to use the Dyno endpoint on the API, but how? Can someone offer an exact example of how I would run the following from the API?

$ heroku run:detached --size 2x rake my_task.rb
like image 648
andy Avatar asked Feb 18 '15 11:02

andy


People also ask

How does Heroku automatically restart dynos?

Automatic dyno restartscreate a new release by deploying new code. change your config vars. change your add-ons. run heroku restart.

How does Heroku work under the hood?

When the Heroku platform receives the application source, it initiates a build of the source application. Under the hood, a git hub webhook is triggered after pushing new Source Code to the master branch. For build and deployment Heroku uses so called buildpacks.

Is Procfile necessary Heroku?

A Procfile is not technically required to deploy simple apps written in most Heroku-supported languages—the platform automatically detects the language and creates a default web process type to boot the application server.

Where do Heroku commands run?

Running Commands on the Heroku Web Interface To use the web console, navigate to your application in Heroku. The same application that you would pass into --app earlier. In the top-right of the interface, there is a “More” button, pressing it displays a “Run Console” option. Select it to add your command.


1 Answers

You can use the platform API to to this, and create a dyno. See https://devcenter.heroku.com/articles/platform-api-reference#dyno-create

By sending a POST request to /apps/your_app_name/dynos with the following parameters:

  • command, the command you wich to run.
  • attach, set it to false.

This will create a one-off dyno and detach it.
This is what the toolbelt does when you run the run:detached command. You can see how it works here: https://github.com/heroku/heroku/blob/01cd753570cb62b917843112fb29d1cdd43ba335/lib/heroku/command/run.rb#L65

like image 58
Damien MATHIEU Avatar answered Oct 05 '22 17:10

Damien MATHIEU