Module: Workers::MassSearchWorker
- Included in:
- MassSearch::ActivitySpreadWorker, MassSearch::ContactScheduleActivityWorker, MassSearch::CustomerAssignRepsWorker, MassSearch::CustomerAutoAssignSalesRepWorker, MassSearch::CustomerDeleteLeadsWorker, MassSearch::CustomerDropSalesRepWorker, MassSearch::CustomerLocatorBlacklistWorker, MassSearch::CustomerLocatorUnblacklistWorker, MassSearch::CustomerLocatorUnwhitelistWorker, MassSearch::CustomerLocatorWhitelistWorker, MassSearch::CustomerOnlineAccountInviteWorker, MassSearch::CustomerScheduleActivityWorker, MassSearch::CustomerSwitchRepRolesWorker, MassSearch::InvoiceRegenerateEdiDocumentsWorker, MassSearch::ItemAddToNextCycleCountWorker, MassSearch::ItemAssignToCatalogWorker, MassSearch::ItemUpdateWorker, MassSearch::OpportunityAssignRepsWorker, MassSearch::OpportunityScheduleActivityWorker, MassSearch::OutgoingPaymentApproveCheckWorker, MassSearch::ProductCatalogAssignToStoresWorker, MassSearch::ProductCatalogSalePriceWorker, SearchResourceUpdateWorker
- Defined in:
- app/concerns/workers/mass_search_worker.rb
Overview
Shared IterableJob behaviour for all search mass-action workers.
Including this module auto-wires Sidekiq machinery and provides:
build_enumerator – loads search/user/locale, initialises progress counters
each_iteration – loads resource, calls process_record, tracks counts, broadcasts progress
on_complete – stores summary and redirects user back to the search page
Progress is broadcast live to the job status page via Turbo Streams using
Workers::StatusBroadcastable (debounced to 500ms), so watchers on /jobs/:id
see a real-time progress bar without polling.
Required args (all string-keyed, JSON-serialisable):
search_id: Integer – the Search to operate on
action_params: Hash – action-specific payload (resource_params, activity params, …)
user_id: Integer – employee performing the action
locale: String – I18n locale (e.g. "en-US")
Contract for including classes:
- Include the module — it self-wires Sidekiq::Job / IterableJob / StatusBroadcastable.
- Override sidekiq_options if needed (default: queue :default, retry 0).
- Implement private #process_record(resource, action_params, user) → true | false
Return true → record counted as updated, SearchResult deleted.
Return false → record counted as error, SearchResult kept.
Implementation note — module inclusion order
Sidekiq::IterableJob defines a default each_iteration that raises NotImplementedError.
To ensure our each_iteration wins in method lookup, the iteration methods live in
the nested Workers::MassSearchWorker::InstanceMethods submodule, which is included into the
worker after Sidekiq::IterableJob. That places InstanceMethods higher in the MRO,
so its each_iteration takes precedence over Sidekiq's default.
Defined Under Namespace
Modules: InstanceMethods
Class Method Summary collapse
-
.included(base) ⇒ void
Wires the including worker class with Sidekiq machinery and the iteration behaviour.
Class Method Details
.included(base) ⇒ void
This method returns an undefined value.
Wires the including worker class with Sidekiq machinery and the iteration
behaviour. Includes Sidekiq modules first so +InstanceMethods+ sits higher
in the MRO and its +each_iteration+ wins.
133 134 135 136 137 138 139 140 141 142 143 |
# File 'app/concerns/workers/mass_search_worker.rb', line 133 def self.included(base) # Sidekiq modules must be included before InstanceMethods so that # InstanceMethods sits higher in the MRO and its each_iteration wins. base.include Sidekiq::Job base.include Sidekiq::IterableJob # StatusBroadcastable wraps Sidekiq::Status::Worker and also pushes live # Turbo Stream broadcasts on every at()/total()/store() call (500ms debounce). base.include Workers::StatusBroadcastable base. queue: :default, retry: 0 base.include InstanceMethods end |