rails periodic task

前端 未结 6 1422
忘了有多久
忘了有多久 2021-02-13 15:19

I have a ruby on rails app in which I\'m trying to find a way to run some code every few seconds.

I\'ve found lots of info and ideas using cron, or cron-like implementat

6条回答
  •  日久生厌
    2021-02-13 15:52

    You can either write you own method, something like

    class MyWorker
      def self.work
        #do you work
        sleep 15
      end
    end
    

    run it with rails runner MyWorker.work There will be a separate process running in the background

    Or you can use something like Resque, but that's a different approach. It works like that: something adds a task to the queue, meanwhile a worker is fetching whatever job it is in the queue, and tries to finish it.

    So that depends on your own need.

提交回复
热议问题