Heroku not fetching from DB when scheduler running - heroku

This just cropped up recently. When the scheduler is running my site goes "empty" and posting to the site produces errors. This never happened a couple weeks ago. Something change with scheduler?
Ruby on Rails app.
1 -> 2x web
0 -> workers
Heroku Postgres :: Yellow
Paying 43ish a month.
Any ideas?

Related

Heroku | Change app to a worker app rather than web

I'm using Heroku Scheduler to run a few apps each night. I believe they are what Heroku would call a "worker apps" because they run for about 2 hours each and only need to run once per day. That said, I can't figure out how to change them from being web apps to worker apps?
For context, I'm using the free tier of Heroku.
You need to create a file called Procfile in your root.
Found the answer here: https://stackoverflow.com/a/44122238/12020295
So, change your Procfile to read (with your specific command filled in):
worker: node index.js
and then also run on CLI:
$ heroku scale worker=1

Scale down Heroku DB from production to hobby

Is it possible to scale down a Heroku DB from production to hobby (the free Dev plan), as long as we stay within the row limits? A site I'm working on requires a production-grade DB for a few weeks, but then it'll be quiet for a while. Haven't been able to find any info on this.
It shouldn't be a problem. Heroku has a guide to upgrade with backups, so I'd recommend taking a backup of your current database, downloading it to your local computer, then spinning up a development database.
Once the development (free) DB is ready, restore from the pgbackup on your local. As long as you're under the row limit, you should be fine.
Obviously, you'd want to put the site in maintenance mode when you do all of this - but it shouldn't be down for more than 5-10 minutes.

AWS Elastic Beanstalk: Launching a new Rails App

I just started using AWS elastic beanstalk to host a web app I wanted to make. However, after following the instructions twice start to finish I get the same end result. Status shows everything is fine, but I keep getting this message:
The status is fine:
And I can view my app on localhost it just doesn't seem to work on beanstalk...
When I first ran eb init these are the settings I chose:
1) US East (Virginia)
2) 64bit Amazon Linux running Ruby 1.9.3
3) No DB instance for now.
Has anyone experienced this problem? What could possibly causing my app to not want to work on beanstalk?
After waiting a couple of hours it finally loaded my index page. I guess it just take a while for my pushed changes to show up.

heroku pgbackups:restore not working

When I run heroku pgbackups:restore DATABASE_URL x123 --confirm app_name
Everything seems to go smoothly in the console but the DB remains empy.
HELP!
Database stats such as table count are populated in the background. For the Starter tier that can be delayed by a few minutes. As #kch mentioned as well, there's some caching involved.
Stats for Production tier are updated more frequently, typically less than 1 minute.

Hot deploy on Heroku with no downtime

A bad side of pushing to Heroku is that I must push the code (and the server restarts automatically) before running my db migrations.
This can obviously cause some 500 errors on users navigating the website having the new code without the new tables/attributes: the solution proposed by Heroku is to use the maintenance mode, but I want a way with no downside letting my webapp running everytime!
Is there a way? For example with Capistrano:
I prepare the code to deploy in a new dir
I run (backward) migrations and the old code continue to work perfectly
I swith mongrel instance to the new dir and restart the server
...and I have no downtime!
You could setup a second Heroku app which points to the same DB as your primary production app and use the secondary app to run your DB migrations without interrupting production (assuming the migrations don't break the previous version of your app).
Let's call the Heroku apps PRODUCTION and STAGING.
Your deploy sequence would become something like:
Deploy new code to STAGING
git push heroku staging
Run database migrations on STAGING (to update PROD db)
heroku run -a staging-app rake db:migrate
Deploy new code to PRODUCTION
git push heroku production
The staging app won't cost you anything since you won't need to exceed Heroku's free tier and it would be pretty trivial to setup a rake deploy script to do this for you automatically.
Good luck!
If you're able to live with two versions of the same app live at the same time, Heroku now has a preboot feature.
https://devcenter.heroku.com/articles/preboot
The only method to improve the process somewhat is what this guy suggests. This is still not a hot deploy scenario though:
http://casperfabricius.com/site/2009/09/20/manage-and-rollback-heroku-deployments-capistrano-style/
One thing I would suggest is pushing only your migrations up to Heroku first and running them before you push your codebase. This would entail committing the migrations as standalone commits and manually pushing them each time (which is not ideal). I'm very surprised there is not a better solution to this issue with all of the large apps hosted on Heroku now.
You actually will have some downtime when Heroku restarts your app. They have a new feature called Preboot that starts up new dynos before taking out the old ones: https://devcenter.heroku.com/articles/labs-preboot/
As for database migrations, that article links to this one on how to deal with that issue: http://pedro.herokuapp.com/past/2011/7/13/rails_migrations_with_no_downtime/
I first commit the migrations, run them, then push the rest of the code. Add a single file like so:
git commit -m 'added migration' -- db/migrate/2012-your-migration.rb
Heroku can't deploy by capistrano. You are block by tool released by heroku.
The no downtime system is impossible in all cases. How change your schema with big change without stop your server. If you don't stop it, you can avoid some change and your database can be inconsistent. SO the using of maintenance page is a normal solution.
If you want a little solution to avoid problem is a balancing in two server. One with only read database during your migration. You can switch to this instance during your migration avoiding the maintenance page. After your migration you come back to your master.
Right now I don't see any possibility to do this without downtime. I hate it too.
This console command does it in the smallest amount of time I can think of
git push heroku master &&
heroku maintenance:on &&
sleep 5 &&
heroku run rails db:migrate &&
sleep 3 &&
heroku ps:restart &&
heroku maintenance:off
git push heroku master to push the master branch to heroku
heroku maintenance:on to put on maintenance so no 500s
sleep 5 to let the dynos start up the new code (without it, the migration might fail)
heroku run rails db:migrate to do the actual migration
heroku ps:restart out of experience the restart makes sure the new dynos have the latest schema
heroku maintenance:off turns of the maintenance
You might have to add -a <app name> behind all heroku commands if you have multiple apps.
Just one command will run these in series in terminal on Mac OSX.

Resources