Created
April 24, 2019 19:36
-
-
Save adamrunner/1cc44b7c4ff829fffd9edcece911a235 to your computer and use it in GitHub Desktop.
pseudo code for the sync_updates implementation for updating multiple models via background job workers when referencing records change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sync_updates to: ProductGroup::Dimension::Option, with: DimensionOption::SyncWorker, fields: [:all], after: [] | |
sync_updates to: Product, # with: Admin::Data::SyncWorker | |
perform(source_class, dest_class, source_id, fields) | |
# finds all types of to models that contain the source_id | |
# e.g. Products that embed property_ids | |
# e.g. ProductGroup::Dimension::Option that have property_id of XXX | |
# enqueues individual update jobs for each record update, using sidekiq batch | |
ProductGroup.where("dimensions.options.property_id" => property_id) | |
perform(source_class, dest_class, source_id, dest_id, fields...) | |
# does the actual updating of fields on the specific models |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment