Class: SeoVisitsSyncWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job, Sidekiq::Status::Worker
Defined in:
app/workers/seo_visits_sync_worker.rb

Overview

Dispatches independently retryable, one-day visit aggregate rebuilds. The
child jobs run on a dedicated one-thread heavy-role capsule, so the initial
90-day backfill is bounded and a shutdown resumes at the unfinished day.

Instance Method Summary collapse

Instance Method Details

#perform(options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})

    Job arguments

Options Hash (options):

  • period_end (Date, String)

    Last day of the refresh window (defaults to today)

  • allow_backfill (Boolean)

    Approve the initial 90-day backfill past the bulk-operation gate



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/workers/seo_visits_sync_worker.rb', line 15

def perform(options = {})
  options = options.with_indifferent_access
  period_end = (options[:period_end] || Date.current).to_date
  query = Seo::VisitPageDailyCountsQuery.new(period_end:)
  refresh_dates = query.refresh_dates

  if initial_backfill_gated?(refresh_dates, options)
    total 1
    at 1, 'Initial visit aggregate requires an approved bulk-operation rollout'
    store info_message: 'Visit aggregation deferred: initial backfill approval required'
    store refresh_days: refresh_dates.size
    report_event(
      'initial_backfill_gated',
      refresh_days: refresh_dates.size,
      period_end: period_end.to_s
    )
    return :initial_backfill_gated
  end

  total 2
  at 1, "Dispatching #{refresh_dates.size} daily visit aggregate(s)..."
  batch = dispatch_refreshes(refresh_dates, period_end)
  report_dispatch(batch, refresh_dates, period_end)
  batch.bid
rescue StandardError => e
  Rails.logger.error("[SeoVisitsSyncWorker] Failed: #{e.message}")
  store info_message: "Visit sync dispatch failed: #{e.message}"
  raise
end