Class: MassSearch::CustomerAssignToSubscriberListWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Status::Worker, Sidekiq::Worker
Defined in:
app/workers/mass_search/customer_assign_to_subscriber_list_worker.rb

Overview

Assigns selected Customers to an existing SubscriberList in the background.
action_params: { subscriber_list_id: }

Instance Method Summary collapse

Instance Method Details

#perform(args = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/workers/mass_search/customer_assign_to_subscriber_list_worker.rb', line 11

def perform(args = {})
  args = args.with_indifferent_access

  search = Search.find(args[:search_id])
  CurrentScope.locale = args[:locale]&.to_sym || :en

  params          = (args[:action_params] || {}).with_indifferent_access
  subscriber_list = SubscriberList.find(params[:subscriber_list_id])
  customer_ids    = search.pinned_query.map(&:resource_id).compact.uniq

  result = Campaign::AssignCustomersToSubscriberList.new.process(subscriber_list, customer_ids)

  if result.subscribed?
    store info_message:  result.messages.to_sentence,
          redirect_to:   Rails.application.routes.url_helpers.search_path(search.id)
  else
    store error_message: result.messages.to_sentence,
          redirect_to:   Rails.application.routes.url_helpers.search_path(search.id)
  end
end