Class: PinterestConversionWorker

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

Overview

Thin worker that delegates to Pinterest::ConversionReporter.

Enqueue after an order is invoiced or an opportunity qualifies, mirroring
the existing GoogleOfflineConversionWorker pattern.

Sidekiq + kwargs caveat. Job args are JSON-serialized into Redis and
unmarshalled back into a plain Array; Ruby keyword arguments don't
survive the round-trip — they arrive as a positional Hash, and a
perform(id:, type:) signature raises ArgumentError: wrong number of arguments (given 1, expected 0; required keyword: id) on dispatch
(AppSignal #5212). Use positional args.

Examples:

Enqueue for an order

PinterestConversionWorker.perform_async(order.id, "order")

Enqueue for an opportunity

PinterestConversionWorker.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 (the model
    type is disambiguated by type).

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

    "order" or "opportunity"



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/workers/pinterest_conversion_worker.rb', line 29

def perform(id, type = "order")
  reporter = Pinterest::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 "PinterestConversionWorker: Unknown type '#{type}' for id #{id}"
  end
end