Class: MicrosoftAdsConversionWorker

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

Overview

Thin Sidekiq worker that delegates to MicrosoftAds::ConversionReporter.

Enqueued from the same Order/Opportunity lifecycle hooks as the other
ad-platform conversion workers (after an order is invoiced / an opportunity
is followed-up), and re-enqueued by ConversionRetrySweepWorker for records
whose last attempt left result = 'failed'.

Sidekiq + kwargs caveat. Job args are JSON-serialized into Redis and come
back as a plain Array; Ruby keyword arguments don't survive the round-trip
(AppSignal #5213). Use positional args — mirrors OpenaiAdsConversionWorker.

Examples:

Enqueue for an order

MicrosoftAdsConversionWorker.perform_async(order.id, 'order')

Enqueue for an opportunity

MicrosoftAdsConversionWorker.perform_async(opportunity.id, 'opportunity')

Instance Method Summary collapse

Instance Method Details

#perform(id, type = 'order') ⇒ Object

Parameters:

  • id (Integer)

    the Order or Opportunity primary key (disambiguated by type).

  • type (String) (defaults to: 'order')

    "order" or "opportunity".



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/workers/microsoft_ads_conversion_worker.rb', line 26

def perform(id, type = 'order')
  reporter = MicrosoftAds::ConversionReporter.new

  case type
  when 'order'
    order = Order.find_by(id: id)
    return unless order

    reporter.send_order_conversion(order)
  when 'opportunity'
    opportunity = Opportunity.find_by(id: id)
    return unless opportunity

    reporter.send_opportunity_conversion(opportunity)
  else
    Rails.logger.error "MicrosoftAdsConversionWorker: Unknown type '#{type}' for id #{id}"
  end
end