I am using sidekiq to run some job after creating a record. when the job tries to find the record with the created ID, there are random cases where it raises a RecordNotFound
. how can this be possible?
class Person
def self.test_create
p = Person.create(
name: 'test'
)
p.run_on_sidekiq
end
def run_on_sidekiq
PersonJob.perform_async(self.id)
end
end
# Sidekiq runs on other server.
class PersonJob
def perform(id)
person = Person.find(id) # sometimes raises RecordNotFound!
# ...
# do something
# ...
end
end
EDIT: as per Alexei's answer, this case was more related with Sidekiq. edited the question to add more detail on Sidekiq usage.