I have a Rails application that pulls information from various internal APIs and stores in a local SQLite DB. My rails application is essentially a glorified UI on top of this data pulled from multiple APIs.
For reasons outside the scope of this question, it is not straightforward to simply update the information in the DB on a periodic basis by re-querying the API. I'm basically forced to recreate the DB from scratch.
In essence I want to do something like this every X hours -
- Automatically shut down the rails application
- Put up a maintenance page ("Sorry, we'll be back in a few mins")
- Drop the db, recreate it, and re-migrate it (
rake db:drop; rake db:create; rake db:migrate) - Run my custom rake task that populates the tables again (
rake myApp:update) - Re-start the application
This brings up a few questions
- How do I have the app restart automatically every X hours? Should I schedule this externally using a cron job? Is there a rails way I can accomplish this?
- How do I display a maintenance page if the app is down? Again, is this also an external re-direct I need to manage?
- Most importantly, is there a good way to drop the tables and recreate them or should I be using
raketasks? Is there a way to callraketasks at startups? I guess I could create a.rbprocess underconfig/initalizersthat would run at startup (but only whenRails.env == 'production')?
Thanks for the help!
Aucun commentaire:
Enregistrer un commentaire