Rails resque: Record not found when passing variab

2019-08-08 04:22发布

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条回答
何必那么认真
2楼-- · 2019-08-08 04:46

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

查看更多
登录 后发表回答