控制器找不到worker创建的对象

时间:2015-10-12 19:56:18

标签: ruby-on-rails ruby-on-rails-4 sidekiq

整天都在努力解决这个问题..

控制器基本上是调用worker来执行“Balance”的创建。工作人员执行成功并创建记录,但是当它返回到控制器时,它找不到创建的对象。如何强制它寻找“更新数据库”记录?

控制器:

  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

工人

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

0 个答案:

没有答案