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

后端 未结 4 1423
半阙折子戏
半阙折子戏 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

    rake is not a method, so you can't invoke it like that here.

    You can either shell out and invoke it, something like

    every(30.seconds, 'Send Messages') {
      `rake scheduler:send_messages`
    }
    

    or rather invoke a new detached process using the heroku API. This is my preferred method right now:

    Heroku::API.new.post_ps('your-app', 'rake scheduler:send_messages')
    

    Heroku::API is available from heroku.rb: https://github.com/heroku/heroku.rb

提交回复
热议问题