Rails resque: Record not found when passing variable from controller to worker

元气小坏坏 提交于 2020-01-24 21:30:12

问题


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

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

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

what can be wrong?


回答1:


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

Had to install the gem that restarts failed jobs.

wrote the post about it



来源:https://stackoverflow.com/questions/9335327/rails-resque-record-not-found-when-passing-variable-from-controller-to-worker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!