Module: Retailer::UrlRediscovery

Defined in:
app/services/retailer/url_rediscovery.rb

Overview

Failure-triggered product-URL rediscovery, shared across retailers.

Catalog product URLs are stable, so we discover them once (per-retailer
backfill) rather than on a schedule. But a URL can go stale when a retailer
renames a slug or re-homes a product, and the probe then fails. This is the
"on failure, re-find the URL" path: when a probe comes back as a URL-type
failure, WebhookResultProcessor enqueues
RetailerUrlRediscoveryWorker, which calls UrlRediscovery.attempt here to cheaply re-find
the URL (no Oxylabs spend) and re-probe.

Each retailer plugs in a strategy object responding to
#discover_url(catalog_item) -> String | nil. Today only rona.ca has one
(sitemap-based); add others by extending UrlRediscovery.strategy_for.

Class Method Summary collapse

Class Method Details

.attempt(catalog_item) ⇒ Boolean

Re-find and persist a fresh product URL for the item, if its retailer has a
rediscovery strategy and a different URL is found.

Parameters:

Returns:

  • (Boolean)

    true when a new, different URL was found and saved



24
25
26
27
28
29
30
31
32
33
34
# File 'app/services/retailer/url_rediscovery.rb', line 24

def attempt(catalog_item)
  strategy = strategy_for(catalog_item)
  return false unless strategy

  url = strategy.discover_url(catalog_item)
  return false if url.blank? || url == catalog_item.url

  catalog_item.update_columns(url: url, url_last_checked: Time.current)
  Rails.logger.info "[UrlRediscovery] #{catalog_item.id} (#{catalog_item.catalog&.name}): url -> #{url}"
  true
end

.available_for?(catalog_item) ⇒ Boolean

Whether the item's retailer has a rediscovery strategy (gates the trigger so
the hot probe path stays a no-op for retailers without one).

Parameters:

Returns:

  • (Boolean)


41
42
43
# File 'app/services/retailer/url_rediscovery.rb', line 41

def available_for?(catalog_item)
  !strategy_for(catalog_item).nil?
end

.strategy_for(catalog_item) ⇒ Object?

Returns a strategy responding to #discover_url, or nil.

Parameters:

Returns:

  • (Object, nil)

    a strategy responding to #discover_url, or nil



47
48
49
50
51
# File 'app/services/retailer/url_rediscovery.rb', line 47

def strategy_for(catalog_item)
  case catalog_item.catalog_id
  when CatalogConstants::RONA_CANADA then Retailer::RonaUrlDiscovery.new
  end
end