问题
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