Class: MicrosoftAdsCampaignSyncWorker

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

Overview

Sidekiq worker: syncs Microsoft Advertising (Bing Ads) campaigns into the
sources table once a day.

Direct parallel to OpenaiAdsCampaignSyncWorker / GoogleAdsCampaignSyncWorker:
every active campaign on the Microsoft Advertising account gets a 1:1
Source record under the "Microsoft Ads" sub-parent (seeded by
..._seed_microsoft_ads_sub_source.rb under the existing "Bing" source).
Campaigns that are paused, or that disappear from the account (deleted,
suspended), are mirrored by setting the local Source's visibility to
:archived rather than destroying the row, so historical attribution on old
visits / orders survives.

Unlike the REST platforms this reads through MicrosoftAds::CampaignManagementClient
(SOAP GetCampaignsByAccountId) and authenticates with the developer token
plus a lazily-refreshed OAuth access token from MicrosoftAds::OauthService.

Scheduled at 02:00 America/Chicago daily — after Google (01:00), OpenAI
(01:15), Pinterest (01:30) and Facebook (01:45) so the API ceilings don't
compete for the same window.

See Also:

Constant Summary collapse

BING_PARENT_SOURCE_ID =

Existing "Bing" source — Websites and Search Engines > Bing (Source 4005).
The "Microsoft Ads" sub-parent the worker fills hangs directly off it,
parallel to the legacy "Bing Ad Campaign" / "Bing Organic Search" nodes.

4005
ADS_PARENT_NAME =

Name of the worker-managed sub-parent under "Bing".

'Microsoft Ads'
ACTIVE_STATUSES =

Microsoft CampaignStatus values (compared case-insensitively) that should
appear as active Source records. Only genuinely-running campaigns qualify:
a paused campaign's Source is archived (it falls out of the active set), and
any campaign that drops out of the API result entirely (Deleted aren't
returned by default) likewise maps to Source#visibility = :archived.

Narrowed from the former active-or-paused set on 2026-06-29 so the nightly
sync stops re-activating the paused-campaign Sources that
ConsolidateMicrosoftAdsSourceTrees marked inactive — only the six live
campaigns stay visible.

%w[active].freeze

Instance Method Summary collapse

Instance Method Details

#performObject

Runs the job.

Returns:

  • (Object)

    the result



53
54
55
56
57
# File 'app/workers/microsoft_ads_campaign_sync_worker.rb', line 53

def perform
  Source.with_advisory_lock('microsoft_ads_campaign_sync', timeout_seconds: 10) do
    sync_campaigns
  end
end