Module: MassSearchWorker

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:

  1. Include the module — it self-wires Sidekiq::Worker / IterableJob / StatusBroadcastable.
  2. Override sidekiq_options if needed (default: queue :default, retry 0).
  3. 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 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