I installed sidekiq to run after_commit, but it does not work (close) to 100% of the time using ActiveRecord::RecordNotFound: Couldn't find User with id=42635.
For the longest time, I thought it was connected to the wrong redis database, but when turned on retry: trueI found that it ended up after 10 minutes.
This is very strange, because I see our users in the admin panel with an id failure, but sidekiq still will not work, and then try again. I have no idea that because of this, I would like it to be possible on the first try.
Edit:
Using AWS, the sidekiq call and worker example below:
In UserObserver:
def after_commit(user)
if user.created_at == user.updated_at
@user = user
identify_and_track
end
...
def identify_and_track
IdentifyAndTrackUserWorker.perform_async(@user.id)
end
Sidekiq employee:
class IdentifyAndTrackUserWorker
include Sidekiq::Worker
sidekiq_options retry: true
def perform(user_id)
@user = User.find user_id
Analytics.identify(
user_id: user_id,
traits: { email: @user.email,
first_name: @user.first_name,
last_name: @user.last_name
}
)
end
end