I would like to know if it is a best design practice to put many database interactions in Sidekiq.
I have a service object that delivers SMS messages to User
. It just retrieves id
of users and calls .perform_async
on a Sidekiq worker class.
The SMS contains many information about other models. Therefore the worker has a long #perform
method that just sets a number of interim variables.
For instance, it is querying tables such as jobs
, bids
, business
, and calling associations on ActiveRecord objects.
Should it be the service's responsibility to retreive all the data, and simply pass those id
s to the worker? Or can I just pass in id
s of user
and let the worker worry about database and associations?
Yes, putting a lot of database work in your worker is totally normal, just remember to stick to Sidekiq's Best Practices.