Controller can't find object created by worker

假如想象 提交于 2020-02-06 05:49:05

问题


Spent all day trying to fix this..

Basically the controller is calling worker to perform the creation of "Balance". The worker performs with success and the record is created but when it returns to the controller it can't find the object created. How to force it looking for the "updated database" records ?

Controller:

  balance = BalanceCreator.perform_async(userx.id, market.id)


  20.times do
    status = Sidekiq::Status::get balance, :exp_status
    if ["done"].include?(status)
      break
    end
    sleep(0.2)
  end

  statux = Sidekiq::Status::get balance, :exp_status
  puts statux
  # Shows correct status

  exp_id = Sidekiq::Status::get balance, :exp_id
  puts exp_id
  # Shows correct id

  user_exp = Balance.find(exp_id)
  # Error - WARN: Couldn't find Balance with 'id'=2

Worker

class BalanceCreator
  def perform(user, market)
    balance = Balance.find_or_create_by(user: user, market: market)

    puts balance.id
    # Correct id displays


    store exp_status: "done"
    exp_status = retrieve :exp_status
    store exp_id: exposure.id
    exp_id = retrieve :exp_id
  end
end

来源:https://stackoverflow.com/questions/33089189/controller-cant-find-object-created-by-worker

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