Skip to content

Instantly share code, notes, and snippets.

@sjl
Created April 6, 2012 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sjl/2321544 to your computer and use it in GitHub Desktop.
Save sjl/2321544 to your computer and use it in GitHub Desktop.

Let's say I make a piece of Clojure code that does something other than serve a website.

Example: a loop that checks twitter every 10 minutes for mentions of some product and emails them to me. You'd start it with lein run and it would run until killed, (Thread/sleep 1000)ing when it doesn't need to work.

Can I host this kind of thing, standalone, on Heroku? With the free plan?

So far it seems like the answer is yes. I just name it something other than 'web' in the procfile (so Heroku doesn't expect it to bind to a port) and then scale it to one process. So the procfile looks like:

scraper: lein run

And I'd run heroku scale web=0 scraper=1 to turn it on.

It would also get killed every so often because I'm on the free plan and I'd have to manually restart it each time, since there's no incoming web requests to keep it alive.

Does all that sound correct?

@kennethreitz
Copy link

Absolutely.

You'd just run heroku scale scraper=1.

Only the free web process type gets idled.

@sjl
Copy link
Author

sjl commented Apr 6, 2012

Oh, cool. So the name web is special cased to mean:

  • Route incoming requests to this process.
  • Kill it after a certain amount of time when on the free plan.

@kennethreitz
Copy link

Exactly.

@technomancy
Copy link

You'll still get it restarted for you on occasion when the dyno gets shuffled to a different box, (generally not more than once a day) but that's different from idling. In either case there's no need to manually restart.

@sjl
Copy link
Author

sjl commented Apr 6, 2012

Interesting... I'm assuming the killing process goes something like this?

  • Send SIGTERM.
  • Wait N seconds.
  • If the process hasn't shut down yet, send SIGKILL.

@kennethreitz
Copy link

Indeed. I'm not sure how long n is, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment