say I\'ve got my rails app on github and am deploying the github repo on heroku.
I\'ve got a situation where I have a simple text file with bunch of words (it is in my g
Put your ruby script in a bin directory and git push it to Heroku. Now you can execute a shell command in the heroku console.
For example, if your Ruby script is bin/foo.rb, you can run the following command in the Heroku console:
`ruby bin/foo.rb`
Note the use of backticks.
cd /path/to/my/local/repository
heroku console
require 'my_word_importing_script'
Failing that, try a simple Sinatra application as importer.rb?
require 'sinatra'
require 'sequel'
configure do
// connect to the database with sequel
end
get '/import/a-long-unguessable-url-fdsjklgfuiwfnjfkdsklfds' do
words = YAML.load(File.join(File.dirname(__FILE__), "my_list_of_words.yaml"))
words.each do |word|
// Your logic for inserting into the database with sequel
end
end
Hitting http://example.com/import/a-long-unguessable-url-fdsjklgfuiwfnjfkdsklfds in your browser would kick off the import. Handy for an external cron task.
You would also need a config.ru file in the repo:
require 'importer'
run Sinatra::Application
Since you're talking about a Rails app on Heroku, how about using rails runner
:
heroku run bundle exec rails runner ./path/to/script.rb -a <your-app>
Have a look at the RailsGuides for rails runner for more details.
Alternatively, turn that script into a rake task if runner is not your cup of tea (eg, for recurring tasks).
With cedar, you can run bash:
heroku run bash
If you want to run arbitrary local Ruby files on Heroku, check out the blog post at
http://www.22ideastreet.com/debug/run-local-scripts-on-heroku
There are some things to watch out for (long run times, etc.) but it might be useful if you have a file that you haven't checked in that you want to test or run on a Heroku instance.