当创建一个新的资源,它需要做一些冗长处理前的资源准备好了,我怎么发送处理掉到背景它不会托起当前请求或其他流量到我的网络应用程序?Ruby on Rails:如何在后台运行事物?
在我的模型:
class User < ActiveRecord::Base
after_save :background_check
protected
def background_check
# check through a list of 10000000000001 mil different
# databases that takes approx one hour :)
if(check_for_record_in_www(self.username))
# code that is run after the 1 hour process is finished.
user.update_attribute(:has_record)
end
end
end
这些天来,最常用的/支持的最好的选择是[sidekiq(https://github.com/mperham/sidekiq),[resque ](https://github.com/defunkt/resque)和[delayed_job](https://github.com/collectiveidea/delayed_job)。恕我直言,Sidekiq是高吞吐量队列的最佳选择,而delayed_job是吞吐量非常低的最佳选择。 – 2013-01-29 03:02:50