Skip to content

Instantly share code, notes, and snippets.

@adamrunner
Created April 24, 2019 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamrunner/1cc44b7c4ff829fffd9edcece911a235 to your computer and use it in GitHub Desktop.
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.
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