Class: OutletPurchaseMatchWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
app/workers/outlet_purchase_match_worker.rb

Overview

Nightly sweep proposing CustomerOutletPurchase links for the orders team
to review — retailer invoices whose ship-to matches an opportunity a rep
worked in the preceding 60 days.

Roughly 90 rows a year, so this is deliberately unclever: one set-based query,
no batching, no ML. Everything it writes lands unverified and nothing it
writes touches the Opportunity.

See Also:

Instance Method Summary collapse

Instance Method Details

#perform(since = nil) ⇒ void

This method returns an undefined value.

Parameters:

Raises:

  • (ArgumentError)

    when since is present but unparseable



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/workers/outlet_purchase_match_worker.rb', line 22

def perform(since = nil)
  lower_bound = parse_since(since)

  # The matcher excludes pairs it has already proposed, but two overlapping
  # runs both read that exclusion before either writes — the losing insert
  # then hits the partial unique index. `timeout_seconds: 0` because a
  # concurrent run has nothing left to find.
  CustomerOutletPurchase.with_advisory_lock('outlet_purchase_match', timeout_seconds: 0) do
    created = Opportunity::OutletPurchaseMatcher.new(since: lower_bound).process

    Rails.logger.info(
      "[OutletPurchaseMatchWorker] proposed #{created.size} outlet purchase link(s) since #{lower_bound}"
    )
  end

  # Outside the lock — an enqueue has no business extending it, and a
  # concurrent run doubling the enqueue is harmless (the transcription
  # service skips anything already transcribed).
  backfill_call_transcriptions
end