how to run a simple file on heroku

后端 未结 5 2052
庸人自扰
庸人自扰 2021-02-05 13:46

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

5条回答
  •  Happy的楠姐
    2021-02-05 13:53

    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
    

提交回复
热议问题