Class: SeoVisitPageDailyRefreshWorker

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

Overview

Rebuilds exactly one daily checkpoint. A dedicated one-thread capsule keeps
these grouped scans sequential and gives Sidekiq a safe boundary between days.

Instance Method Summary collapse

Instance Method Details

#perform(visit_date, position = 1, total = 1) ⇒ Object

Runs the job.

Parameters:

  • visit_date (Date)

    the visit date

  • position (Integer) (defaults to: 1)

    the position to evaluate

  • total (Integer) (defaults to: 1)

    the total to evaluate

Returns:

  • (Object)

    the result



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/workers/seo_visit_page_daily_refresh_worker.rb', line 16

def perform(visit_date, position = 1, total = 1)
  started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  result = Seo::VisitPageDailyCountsQuery.new(period_end: visit_date.to_date).refresh_date!(visit_date)
  duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - started_at

  tags = { visit_date: result.fetch(:visit_date).to_s }
  if defined?(Appsignal) && Appsignal.active?
    Appsignal.add_distribution_value('seo.visit_aggregate.duration_seconds', duration, tags)
    Appsignal.add_distribution_value('seo.visit_aggregate.source_visits', result.fetch(:source_visits_count), tags)
    Appsignal.add_distribution_value('seo.visit_aggregate.pages', result.fetch(:page_count), tags)
  end

  Rails.event.notify(
    'seo.visit_daily_aggregate',
    action: 'completed',
    position:,
    total:,
    duration_seconds: duration.round(1),
    **result
  )
end