Ruby on Rails: How to run things in the background?

前端 未结 7 1947
暖寄归人
暖寄归人 2020-12-07 12:32

When a new resource is created and it needs to do some lengthy processing before the resource is ready, how do I send that processing away into the

7条回答
  •  忘掉有多难
    2020-12-07 13:02

    What about:

    def background_check
       exec("script/runner check_for_record_in_www.rb #{self.username}") if fork == nil
    end
    

    The program "check_for_record_in_www.rb" will then run in another process and will have access to ActiveRecord, being able to access the database.

提交回复
热议问题