I have problem with calling worker inside another worker with sidekiq. I have a two workers that looks like this:
class UserExportWorker
include Sidekiq::Worker
sidekiq_options queue: :users, unique: true, retry: false
def perform(user_id)
# code that exports user to external service via API
UserExportStatusWorker.perform_in(1.minute, user_export_id, user_id)
end
end
class UserExportStatusWorker
include Sidekiq::Worker
sidekiq_options queue: :users, unique: true, retry: false
def perform(user_export_id, user_id)
# code that check if exporting user to external service via API is finished
if export.completed?
user.update(status: 'exported')
else
UserExportStatusWorker.perform_in(1.minute, user_export_id, user_id)
end
end
end
UserExportWorker exports user to some external service via API and run UserExportStatusWorker that will check if export in external API is finished and, if its not then it will launch the same worker again, when export will finish it will update user state column in database. The problem is that UserExportStatusWorker is not updating user in database even if export to external API is successfull. But when I change my code to this:
class UserExportWorker
include Sidekiq::Worker
sidekiq_options queue: :users, unique: true, retry: false
def perform(user_id)
# code that exports user to external service via API
UserExportStatusWorker.new.perform(user_export_id, user_id)
end
end
class UserExportStatusWorker
include Sidekiq::Worker
sidekiq_options queue: :users, unique: true, retry: false
def perform(user_export_id, user_id)
# code that check if exporting user to external service via API is finished
if export.completed?
user.update(status: 'exported')
else
UserExportStatusWorker.new.perform(user_export_id, user_id)
end
end
end
I'm completely out of ideas... Why this not works?
UserExportStatusWorkerare getting enqueued withperform_in? - Anthonyretry: trueand watch the retry queue in the UI to see if the job is failing. I use rollbar but he recommends a few - github.com/mperham/sidekiq/wiki/Error-Handling - Anthony