Sidekiq not finding object in worker

Viewed 874

When I create a new User in my app, I run an after_create method which then asynchronously triggers a Sidekiq worker.

This worker ...

def perform user_id
    @user = ::User.find user_id
    # ...
end

... always returns the following error:

ActiveRecord::RecordNotFound: Couldn't find User with 'id'=315928979197048617

But using the rails console to check if the User id findable:

User.find(315928979197048617)
=> #<User id: 315928979197048617>

Does this happen because the creation of the new User takes some time and the worker has already performed the method when finished? If, how would I fix that behavior?

1 Answers
Related