Tag: 背景过程

Rails resque:将变量从控制器传递给worker时未找到记录

我有一个非常简单的控制器: def create @poem = Poem.new(params[:poem]) @poem.prose = @poem.content @poem.save Resque.enqueue(PoemWork, @poem.id) …. 一个非常简单的工人: class PoemWork @queue = :poem_queue def self.perform(poem_id) @poem = Poem.find(poem_id) txt = @poem.content #do stuff here @poem.save end end 而且我一直得到“找不到id = 53的诗”或smth。 像那样… 我尝试只传递字符串,只是整数等..但它也以ActiveRecord :: RecordNotFound结束 什么可能是错的?

在后台进程中分叉和线程有什么区别?

阅读它所述的spawn gem的文档: 默认情况下,spawn将使用fork来生成子进程。 您可以将其配置为通过在调用时通过告知spawn方法或通过配置环境来执行线程化。 例如,这就是告诉spawn在调用时使用线程的方法, 使用fork或thread之间的区别是什么,这两个决定的影响是什么,以及我如何知道使用哪个?

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