I am running a web application on heroku.
I have a couple cron jobs running on my server at 9am, 12pm, and 12am.
I need my web page to not have idled for me to run these cron jobs. As such I need some way to ping the web page just before these times to make sure it is running so that these cron jobs can be executed. I've seen uptime robot and new relic but they seem to only ping all the time for set intervals whereas I want to ping my webpage at specific times.
You can do one of two things:
Use the Heroku Scheduler addon to ping your dyno by making a request to it before the time you need your dyno to be awake, OR
You can pay for a normal dyno. Heroku doesn't idle the normal dynos, only the free ones.
You could configure a Heroku Scheduler to run and to wake up your web dyno by pinging it just before the time you need your web dyno to wake up.
Related
I'm testing an app with a worker and a web dyno on Heroku free tier and I'd like to keep the worker alive to be able to execute background tasks while letting the web dyno idle. By default they both go idle in 30 mins even if I have things queued on the worker.
I understand there're ways to keep the web dyno alive (and with that the worker as well), and there're ways to keep the web alive while scaling down the worker. However I'd need the worker alive and the web in idle.
I tried running a recurring job on the worker which would
Restart the dyno.
Scale the dyno down and then back up.
Both approaches worked (as in they restarted and scaled the dyno correctly) but the worker dyno would still idle after 30 mins (as if it's dependent on the web dyno). Edit: yep, that's pretty much the case as explained here: https://devcenter.heroku.com/articles/free-dyno-hours#dyno-sleeping
I could do this form the outside but it seems I'd have to constantly check for the state since a new restart doesn't seem to give me 30 mins headway. I'd also have to expose the API key which I'd like to avoid.
If I've gotten you right, you're trying to stop the web dyno and leave the worker dyno alive.
You could do that by going to the Resources tab:
And then in the 'web' section:
Press the pencil, toggle it off and press 'Confirm'.
As a workaround I currently remove the web dyno and explicitly enable it when I need it. As explained here:
Worker-only Free dynos do not sleep since they do not respond to web
requests.
My workaround was to just create two apps that deploy automatically from the same repository. Then, all you would need to do is enable the worker dyno for one and the web dyno for the other.
I'm a little bit confused about the whole dyno business with heroku . On their site, they define a dyno as:
A dyno is a lightweight Linux container that runs a single
user-specified command. A dyno can run any command available in its
default environment (what we supply in the Cedar stack) or in your
app’s slug (a compressed and pre-packaged copy of your application and
its dependencies).
This (somewhat?) makes sense in my head, but when I think about dynos in the context of multiple dynos running for one web app, my brain gets twisted.
Lets I'm building a web app with a server which runs a very important task only once every 3 hours for all users. If I am running multiple web dynos for this site, does that mean there is a separate server instance running on each dyno? And would that very-important-task that is run every 3 hours be run on each dyno every 3 hours?
Thanks a lot for any clarification!
Each dyno is an LXC container running in one of the heroku instances.
Depending of your dyno size, there might be other containers on the same instance or not.
But the rough idea is that yes, each dyno you have running is a different instance, and a task set to run on any web dyno each 3 hours will run on all of them.
You may want to look into the heroku scheduler addon. It will run a one-off dyno at a specified interval, allowing you to run cron-like tasks.
I want to add scheduled jobs in Openshift, which would be getting added dynamically to my application. I had tried the cron service on Openshift, but it stops after certain amount of time. I want to add a service similar to Iron workers or heroku workers, but these services seem to be costly. Also is it possible to implement such a service on our own in Openshift?
First off, I'm guessing your Cron service is stopping when your application idles. Idling occurs when your app doesn't receive web traffic for 24 hours. Just upgrade to the Bronze plan to remove idling (it's free).
Second off, you can add IronWorker as an Add-on Service through the OpenShift Marketplace: https://hub.openshift.com/addons/10-ironworker
If you're using Ruby you could also just run Resque with Redque Scheduler along with the downloadable Redis cartridge:
Resque/Resque Scheduler: https://github.com/resque
Redis: https://hub.openshift.com/addons/34-redis
I have recently added "Heroku Scheduler" addon to my heroku app...
I currently have a free heroku account and have the standard one web dyno....
Now I have set up a scheduled comment to run with scheduler... What will happen if I keep having 0 Worker dynos....
Do I get charged?
Does my task just not run?
Or does it fall back to the web dyno and gets queued on that one?
Your scheduled task with scheduler will run when you tell it to. It is similar to a worker process, however it runs then stops running once its finish instead of continually being billed. You are billed for the time it runs, but only that time. If your task is a short task running for 1 minute, on an hourly basis then you'd be billed at 24 minutes a day.
Just as an update to my previous comment, all the above as been obviated by the recent dyno and billing changes on heroku. You can now have a free web+workder dyno, provided it sleeps for at least 6 hours per day. There are also other changes making it cheaper to run a small hobby type project, even 24 hours per day.
https://devcenter.heroku.com/articles/usage-and-billing
As Craig mentioned, the scheduler addon will run a task for a set amount of time. It will use the time from your web dyno and it will not spawn a new dyno to complete the task. As a result, your web traffic will be queued during that duration (this is my current understanding of using the scheduler addon for heroku).
I currently have an app deployed on Heroku which runs on two web dynos so it won't go to sleep if it remains inactive for a certain time.
Now if I scale it down to only one web dyno (free) and instead pay for one worker dyno, will Heroku always keep my app active?
It will still idle - you NEED to have more than a single web dyno
https://devcenter.heroku.com/articles/dyno-idling
You can also use the New Relic add-on to monitor your app and keep it alive. There is a tab in settings to configure availability monitoring.
You can also avoid a single web dyno from idling by using a monitoring service like pingdom.com since it's periodically sending a request to your web dyno.
Try Pingdom. Free plans include one website check. I use this service to keep my app active all the time.
Pingdom tests your websites and other infrastructure components as
often as every minute to make sure it is all up and running.
From Pingdom Homepage
Pingdom does this by "pinging" or rather requesting a resource from your website on a regular interval. This has the side effect of keeping your website "active", cache's primed, etc.. because your website is seeing regular "traffic" (the requests coming from pingdom).
Try Un-idler. You don't need to sign in and it's free.
http://unidler.herokuapp.com/
You can try http://kaffeine.herokuapp.com/ it will ping your app every 30 minutes so your app won't go to sleep.
Try CloudUp. It visits your apps periodically to keep them awake. It is free, and you can add as many apps as you want. It also activates apps on Google App Engine and Azure.