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).
Related
Heroku automatically sleeps the application afrer some time in the low price tiers which is a nice thing as it reduces the cost. But in a spring boot appllication the schedulers wont run when in sleep. Does heroru offer functionality to the wake-up the app so the schedulers will run?
Pinging every 30 minutes to have the app up and running does not suffice because the app will stay up even if it is idle. I would like to somehow wake up the app before a scheduler is about to run and then let is sleep back again if it is not used until a scheduler have to run again (or someone calls the api)
Your best bet is to move your job scheduling out of the main application. That way it doesn't have to be awake for jobs to run.
One way to do that is via the Heroku Scheduler:
Scheduler is a free add-on for running jobs on your app at scheduled time intervals, much like cron in a traditional server environment
Essentially, you can add jobs by providing a command to run and a frequency. The scheduler will kick the job off at the desired time.
Timing isn't guaranteed to be perfect, and very occasionally jobs may not run at all. But this is the most affordable option, and it has worked well for me in the past. For more precise and guaranteed timing you need to run at least one dyno continuously.
I have an application that is hosted on Heroku. The application has a process that is run on the server, that the user has the ability to start and stop. Once the user clicks 'Start', the process is supposed to stay running until the user presses 'Stop'. The functionality of the app should allow that the process can be run for extended periods of times (6 months or so) continuously.
I have deployed my app on a Heroku free dyno. While reading the Heroku documentation, I came across this page that states that Heroku Dynos are restarted automatically every 24 hours. Here is the relevant passage:
Dynos are also restarted (cycled) at least once per day to help maintain the health of applications running on Heroku. Any changes to the local filesystem will be deleted. The cycling happens once every 24 hours (plus up to 216 random minutes, to prevent every dyno for an application from restarting at the same time). Manual restarts (heroku ps:restart) and releases (deploys or changing config vars) will reset this 24 hour period. Cycling happens for all dynos, including one-off dynos, so dynos will run for a maximum of 24 hours + 216 minutes. If you have multiple dynos, they should cycle at different times based on the random 0 to 216 minutes difference. If you continually make changes to your application without a 24 hour gap, you won’t see cycling at all.
Does this mean that the user process that he/she has started will automatically be stopped when the dyno restarts? If yes, does it automatically resume the user process where it left off?
If not, I will have to find a different hosting solution since the process may need to be run 24x7x365.
Does this mean that the user process that he/she has started will automatically be stopped when the dyno restarts?
Yes it does. As it will when you change config variables, or deploy updates, or add / remove addons.
If yes, does it automatically resume the user process where it left off?
No it doesn't. Any safe-and-resume behaviour you have to implement in your application. When stopping processes, Heroku will send them a SIGTERM signal and give them 30 seconds to safe their work.
If not, I will have to find a different hosting solution since the process may need to be run 24x7x365.
I doubt that there is any hosting solution that will give you what you want. In a cloud environment restarts are a thing that happens all the time, at least for you updating your application, bugfixes, security fixes. Every hosting provider or platform that provides you with 24x7x365 uptime will also restart and replace your dynos all the time.
I am given the following problem:
There are two shifts. One shift starts at 12am and the other at 12pm.
At the beginning of each shift, generate some tasks (details not important).
Ordinarily, this is a trivial problem that can be solved with crontab. However, my company is running on Heroku and the Heroku Scheduler has the following interesting properties:
It can only run every 10 mins, hour or daily,
You cannot time when the scheduler will actually start. If you scheduler is running every 10 mins, all you can expect is that it will run between 4:00am to 4:10am.
It is possible that the scheduler encounters some error and crash. When this happens, the scheduler will restart immediately. As an example, if the scheduler crashed at 4:00 while it was running, it might run again at 4:01.
Is it possible to implement a cronjob that:
executes once only once after 12am and 12pm
without needing a database to track its execution time?
One way I can think of doing this would be to have some cron server (not on Heroku) which runs a script at 12am and 12pm.
The script invoked by the cron could use the Heroku Platform API to spin up a one-off dyno in your Heroku app (using the Dyno Create endpoint).
This method satisfies your requirements of executing only once at 12am and at 12pm, WITHOUT using a DB to track execution times.
The drawback of this method is that it is not a "pure Heroku" solution, and requires you to maintain some "external" server to trigger your cron jobs.
If you don't like the ideas of maintaining your own cron server for that, you could use some cloud solution to schedule your script. For example, I would imagine you could do this for free using AWS Lambda with Scheduled Events.
In this case, you would schedule your lambda function to run each day at 12am and 12pm, and your lambda function would spin up your Heroku one off dyno.
Of course if you would be willing to add some form of DB to your Heroku app, you could easily create a "pure Heroku" solution.
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.
If I update an application running on Heroku using git push and this application is running on multiple dynos - how is the upgrade process run by Heroku?
All dynos at the same time?
One after another?
...?
In other words: Will there be a down-time of my "cluster", or will there be a small time-frame where different versions of my app are running in parallel, or ...?
well can not tell the internal state but what i have experienced is
Code push complete
Code compiled (slug is compiled )
After that all dynos get the latest code and get restarted. (restart take up to 30 seconds or so and during this time all requests get queue).
So there will be no down time as during the restart process all the requests get queued and there i dont think that that multiple versions of your code will be running after the deployment.
Everyone says there's 'no downtime' when updating a Heroku app, but for your app this may not be true.
I've recently worked on a reasonably sized Rails app that takes at least 25 seconds to start, and often fails to start inside the 30 seconds that Heroku allows before returning errors to your clients.
During this entire time, your users are waiting for something to happen. 30 seconds is a long time, and they may not be patient enough to wait.
Someone once told me that if you have more than 1 dyno, that they are re-started individually to give you no downtime. This is not true - Heroku Stops all dynos and then Starts all Dynos.
At no time will there be 2 versions of your app running on Heroku