Class: PinterestCampaignSyncWorker
- Inherits:
-
Object
- Object
- PinterestCampaignSyncWorker
- Includes:
- Sidekiq::Job
- Defined in:
- app/workers/pinterest_campaign_sync_worker.rb
Overview
Sidekiq worker: syncs Pinterest Ads campaigns into the sources
table once a day.
Direct parallel to GoogleAdsCampaignSyncWorker and
OpenaiAdsCampaignSyncWorker: every active or paused campaign on the
Pinterest ad account gets a 1:1 Source record under the "Pinterest
Ads" sub-parent (seeded by
20260515074600_seed_pinterest_ads_and_organic_sub_sources.rb).
Archived campaigns are mirrored by setting the local Source's
visibility to :archived rather than destroying the row, so
historical attribution on old visits / orders survives.
Scheduled at 01:30 America/Chicago daily — 30 minutes after the
Google Ads sync (01:00) and 15 minutes after the OpenAI Ads sync
(01:15) so the three API ceilings don't compete for the same window.
Authenticates via Pinterest::OauthService (OAuth 2.0, auto-refreshing) —
when the ad account hasn't been connected yet the worker logs and skips
rather than raising, so an unconnected integration never floods AppSignal.
Constant Summary collapse
- ACTIVE_STATUSES =
Pinterest campaign status values that should appear as active
Source
records. "ARCHIVED" maps to localSource#visibility = :archived.
Pinterest uses uppercase status values (vs OpenAI's lowercase). %w[ACTIVE PAUSED].freeze
Instance Method Summary collapse
Instance Method Details
#perform ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/workers/pinterest_campaign_sync_worker.rb', line 36 def perform unless Pinterest::OauthService.new.connected? logger.info 'PinterestCampaignSyncWorker: Pinterest OAuth not connected — skipping. ' \ 'Connect the ad account at /pinterest/oauth/authorize.' return end Source.with_advisory_lock('pinterest_campaign_sync', timeout_seconds: 10) do sync_campaigns end end |