本文介绍了Rails resque:将变量从控制器传递给工作程序时找不到记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的控制器:

I have a very simple controller:

def create
  @poem = Poem.new(params[:poem])
  @poem.prose = @poem.content
   @poem.save
   Resque.enqueue(PoemWork, @poem.id)
 ....

和一个非常简单的工作者:

and a very simple worker:

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.这样...

And I keep getting "Couldn't find Poem with id=53" or smth. like that...

我尝试仅传递字符串,仅传递整数等.但是它也以ActiveRecord :: RecordNotFound结尾

I tried passing just string, just integer etc.. but it also ends with ActiveRecord::RecordNotFound

怎么了?

推荐答案

所以问题是工作程序在实际创建对象之前启动.

So the problem was that the worker starts before the object actually gets created.

必须安装可重新启动失败作业的gem.

Had to install the gem that restarts failed jobs.

撰写了有关此内容的帖子

这篇关于Rails resque:将变量从控制器传递给工作程序时找不到记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 07:47