Class: AudiencesSyncWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job
Defined in:
app/workers/audiences_sync_worker.rb

Overview

Sidekiq worker: daily multi-platform audience reconcile. Drives every enabled
adapter (Google Customer Match, OpenAI custom audiences, …) over every segment
via Marketing::Audiences.sync. Defaults to validate-only; the schedule passes
live = true once the go-live checklist in sidekiq_production_schedule.yml is
cleared. One advisory lock guards the whole pass so a slow run can't overlap
its next tick.

Instance Method Summary collapse

Instance Method Details

#perform(live = false) ⇒ void

This method returns an undefined value.

Parameters:

  • live (Boolean, String) (defaults to: false)

    false (default) validates only across all
    adapters; truthy performs real uploads. .to_b keeps a serialized "false"
    falsey (plain !live would treat the string "false" as truthy → live).



35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/workers/audiences_sync_worker.rb', line 35

def perform(live = false)
  live = live.to_b
  ran = ApplicationRecord.with_advisory_lock('marketing_audiences_sync', timeout_seconds: 0) do
    results = Marketing::Audiences.sync(validate_only: !live)
    failures = results.reject(&:ok)
    logger.info("[AudiencesSyncWorker] live=#{live} steps=#{results.size} failed=#{failures.size}")
    raise "AudiencesSyncWorker failures: #{failures.map { "#{it.adapter}/#{it.scope}" }.join(', ')}" if failures.any?

    true
  end
  raise 'AudiencesSyncWorker skipped — another reconcile holds the lock' unless ran
end