script/runner in rails 3

前端 未结 2 1504
被撕碎了的回忆
被撕碎了的回忆 2021-01-11 09:48

I have 2 jobs I would like to run and they are dependant on Models in my rails application. I added the ruby files in a separate folder called Jobs, that I have appended to

相关标签:
2条回答
  • 2021-01-11 10:12

    Use rails runner

    $ rails -h
    Usage: rails COMMAND [ARGS]
    ...
    runner       Run a piece of code in the application environment
    
    All commands can be run with -h for more information.
    
    0 讨论(0)
  • 2021-01-11 10:24

    The "Rails 3 way" to do this is with Rake using the :environment prerequisite, which loads the Rails environment. Like so:

    task :name => :environment do |t|
      # actions
    end
    

    In the block you can load and execute your jobs.

    If you haven't written Rake scripts before, here's a good tutorial. It's quite easy.

    0 讨论(0)
提交回复
热议问题