2016-10-17 7 views
2
class A 
    .... 
    def something 
    if condition 
     mark_completed 
     // here I can see the object progress is completed 
     CompletionStatsWorker.perform_async(self.id) 
    end 
    end 

    def mark_completed 
    self.update_attributes!(progress: 'completed') 
    end 
end 

をフェッチ:Sidekiqは、労働者には一貫性のないデータ

class CompletionStatsWorker 
    include Sidekiq::Worker 

    def perform(id) 
    obj = A.find(id) 
    //here I'm getting the progress of the same object as 'progressing' 
    end 
end 

Sidekiqは何とかそれが成功したフィールドupdation後にトリガされた場合でも、古いデータを取得します。オブジェクトupdated_atは実際のupdated_atの値と同じではないことがわかります。 sidekiqが速く、それはDBにコミットよりも動作しますので、それが起こることがあり

答えて

2

、あなたがCompletionStatsWorker.perform_async(self.id)after_commitへのコールバックや変更方法を追加する必要があります助けてください:見sidekiq docs

+0

を取る

def something if condition if mark_completed // here I can see the object progress is completed CompletionStatsWorker.perform_async(self.id) end end end 

ねえオレグは、I」両方を試みた。奇妙なことは、私が労働者を呼ぶ前に進行が完了していることです。しかし、労働者の中では、状況は進行中であると再び表示されます。しかし、dbでは、それは完了しました。 –

+0

'mark_completed'メソッドの後に' sleep 1'を追加するだけで、チェックのために試してみることができます。この場合も同じですか? –