script/runner in rails 3

前端 未结 2 1503
被撕碎了的回忆
被撕碎了的回忆 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: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.

提交回复
热议问题