Answer the question
In order to leave comments, you need to log in
Why is the object not saved when executing a deferred method through Sidekiq?
When creating an object, I want a few more methods to be executed deferred:
Object:
after_create :process_offer
protected
def process_offer
BodyWorker.perform_async(self.id)
end
class BodyWorker
include Sidekiq::Worker
sidekiq_options retry: false
def perform(offer_id)
offer = Offer.find(offer_id)
remove_html(offer)
offer.publish!
end
protected
def remove_html(offer)
offer.body = ''
offer.save
end
Answer the question
In order to leave comments, you need to log in
It is strange that the worker does not crash, because to call the worker after saving, you need to use after_commit and not after_create. At the moment when after_create is called, the transaction has not yet ended and the id is available only in the model.
However, this worker does not execute the remove_html method, or executes it, but the result is not saved, I do not understand why.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question