How do I use Rails clockwork gem to run rake tasks?

后端 未结 4 1447
半阙折子戏
半阙折子戏 2021-01-02 03:23

What is the syntax for calling rake tasks from clockwork? I\'ve tried all kinds of syntax, and nothing seems to work. (I\'m specifically interested in clockwork because Her

4条回答
  •  死守一世寂寞
    2021-01-02 04:06

    You can add the following method to your clock.rb file:

    def execute_rake(file,task)
    require 'rake'
    rake = Rake::Application.new
    Rake.application = rake
    Rake::Task.define_task(:environment)
    load "#{Rails.root}/lib/tasks/#{file}"
    rake[task].invoke
    end
    

    and then call

    execute_rake("your_rake_file.rake","your:rake:task")
    

    in your handler

提交回复
热议问题