How to set up a periodic nodeJS worker on Heroku Cedar - heroku

I've got an Express Web app running as my main app on Heroku Cedar. I need to run a worker job periodically. I know I can specify a worker: in my Procfile, but that seems to be for a forever running kind of job. Perhaps there is a way to have the event mechanism of nodeJS caus e the worker to Idle, and use Cron to poke it alive periodically??

to keep your process alive you can try using an external service which will "ping" your application, you can use the newrelice free addon on heroku for that.
I am currently experimenting and it seems that even with this the application is still put in idle mode but it restarts on the next "ping" so it is still up most of the time.
I don't known node.js but I do my worker with Ruby+EventMachine inside a ruby on rails application and it works fine, you just need something to work in the background aside of your web requests.

Related

Set up Heroku log drain on worker process?

I set up a log drain for my Heroku app that drains the logs via HTTPS.
I added it to my app with this toolbelt command:
heroku drains:add http://example.com --app MY_APP
Trouble is I have a chron job that runs on a separate dyno, my worker process, and that isn't draining.
I really only want to drain the logs from the worker process.
Is there a way to add a drain to ONLY the worker process? Barring that, is there a way to make it so the worker process is included in the drain?
Thanks!
At this point in time it seems not possible to filter a drain on anything.
The drain contains ALL logging from the specified app and all dynos in that app.
the only fix right now seems to be using a filter on the receiving end.

Heroku: Prevent worker process from restarting?

I have a Heroku worker setup to do a long running job which iterates over long periods. However whenever I do an update & deploy of other files in the repo this worker restarts, which is annoying, any way to avoid this?
No. This behaviour is part of Heroku's Automatic Dyno Restarting.
You can't work around this. Instead, you need to build all parts of your app to be able to function properly despite the fact that all dynos will restart at least once every 24 hours or so, whether or not you deploy updates in your repo.
Most significantly, you need to build support for Graceful Shutdown into all your processes (e.g. web process and worker processes).

Background process in ruby script with heroku

I want to get info from twitter for my project, I'm using tweetstream gem, and it works in my code, but I need it to be done as a background process in heroku as a script. So I'm using Event Machine gem to do so, and it works in my computer, but I haven't been able to make it run on heroku on it's own.
I've read that I need to use the Procfile and say it is a worker process, but I can't make it work, but on my local it works fine.
I'm new to background process and working with servers.
Heroku dynos do not support background processes in the "free" or "hobbyist" tiers.
Here is the Heroku Documentation on Background Jobs.
It costs about $30 bucks a month to add this on. There is other implementation hurdles to overcome with a local server vs. Heroku with background jobs. The best starting point I can give you is that Heroku does not support background jobs by default. You have to "Scale the worker dynos"

Is there any down time when committing to a clojure app running on Heroku?

Is there any potential downtime when I do a commit to a clojure/Java app running on Heroku?
I am guessing not - but can't find out for sure.
Thanks.
When you push to Heroku, you invoke the slug compiler, which does all the heavy lifting needed to turn your application into a self-contained archive. That can take a little while, as you see whenever you run git push. However, during this time, your application is running normally.
When your slug finishes compiling, Heroku then pushes it out to the dyno grid. This causes existing web dynos to stop and causes new ones to start. Your application will be unresponsive between the time that the old dynos stop and the new ones begin serving requests -- probably only a few seconds. During this interval, Heroku's routing layer will queue incoming requests.
TL;DR: users might notice a pause (but not an error!) as your application is updated. You can simulate this at any time by running heroku restart.

how do i debug a node.js app using heroku foreman?

i am new to heroku and node.js. i have a small node.js app which i can start and run successfully on my local machine using FOREMAN from the heroku toolbelt. i do not understand how to best debug the app, though.
i see that there is an eclipse debugger for node.js as well as the node-inspector project. but i cant seem to make these work with FOREMAN.
foreman start
if it is not possible to debug an app started by foreman, what is the purpose of foreman?
Just an addition, your Procfile could look like this:
web: node web.js
webDebug: node --debug-brk=5858 web.js`
So to start debugging you just call foreman start webDebug, you could call the configuration however you want.
The debugger will listen on port 5858 and you'll have to call your app from http://localhost:5100 instead of http://localhost:5000.
The purpose of Foreman is to allow you to run complex applications, which may consist of several processes, easily. Check out the author's blog post on Foreman:
Lately I've noticed my web apps are getting complicated to run. My
apps no longer consist of a single web process; I usually have have
one or more types of background workers to run different types of jobs
and a clock process to handle scheduling. Splitting an app up in this
way is great for performance and scalability. The downside, however,
is that it becomes much more complicated to get the app and all of its
parts running.
Foreman is an attempt to make this easier. Using foreman you can
declare the various processes that are needed to run your application
using a Procfile.
By leveraging Foreman, Heroku has made it so that you can essentially run any kind of process you want to--a Rails app, a Sinatra app, a Node.js app, or anything else--simply by specifying how to start it in your Procfile, which Foreman reads and executes.
Foreman also allows you to take this simple Procfile and export it to production environments using tools like Upstart and Init. It does not provide any debugging functionality (nor is it meant to).

Resources