Class: Marketing::CustomerMatch::AudienceRemoval

Inherits:
Object
  • Object
show all
Defined in:
app/services/marketing/customer_match/audience_removal.rb

Overview

Daily counterpart to AudienceSync: removes members who must no longer be in
ANY Customer Match list — opted out ("take me off your list"), closed,
bankrupt, guest, or inactive (Customer.marketing_suppressed, the exact
complement of the eligible+consented set the sync ingests). Reusing the
deterministic MemberBuilder means the removal reproduces exactly the
identifiers that were uploaded; removing a non-member is a no-op, so the same
suppressed set is removed from every list, statelessly.

Defaults to validate_only; a live run is opt-in (the daily schedule passes
validate_only: false).

See Also:

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(validate_only: true, client: Client.new) ⇒ AudienceRemoval

Returns a new instance of AudienceRemoval.

Parameters:

  • validate_only (Boolean) (defaults to: true)

    true (default) dry-runs the removal

  • client (Client) (defaults to: Client.new)


33
34
35
36
# File 'app/services/marketing/customer_match/audience_removal.rb', line 33

def initialize(validate_only: true, client: Client.new)
  @validate_only = validate_only
  @client = client
end

Class Method Details

.callResult

Returns:



29
# File 'app/services/marketing/customer_match/audience_removal.rb', line 29

def self.call(**) = new(**).call

Instance Method Details

#callResult

Returns:



39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/services/marketing/customer_match/audience_removal.rb', line 39

def call
  removed = 0
  requests = 0
  MemberBuilder.new(Customer.marketing_suppressed).each_batch do |batch|
    list_ids.each do |list_id|
      @client.remove(user_list_id: list_id, members: batch, validate_only: @validate_only)
      requests += 1
    end
    removed += batch.size
  end
  Result.new(removed:, lists: list_ids.size, requests:, validate_only: @validate_only)
end