Class: SeoVisitPageDailyRefreshFinalizer

Inherits:
Object
  • Object
show all
Defined in:
app/workers/seo_visit_page_daily_refresh_finalizer.rb

Overview

Applies SiteMap metrics only after every required daily checkpoint has landed.

Instance Method Summary collapse

Instance Method Details

#on_complete(status, options) ⇒ Object

Parameters:

  • status (Sidekiq::Batch::Status)

    batch status for the daily checkpoints

  • options (Hash)

    batch payload serialized by the dispatcher

Options Hash (options):

  • started_at (String)

    ISO8601 time the batch started

  • refresh_days (Integer, String)

    number of days refreshed

  • period_end (String)

    last date included in the refresh



10
11
12
13
14
15
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_finalizer.rb', line 10

def on_complete(status, options)
  duration = Time.current - Time.iso8601(options.fetch('started_at'))
  failures = status.failures.to_i
  period_end = options.fetch('period_end')

  Rails.event.notify(
    'seo.visit_sync',
    action: 'aggregate_completed',
    batch_id: status.bid,
    failures:,
    refresh_days: options.fetch('refresh_days').to_i,
    duration_seconds: duration.round(1),
    period_end:
  )

  if defined?(Appsignal) && Appsignal.active?
    Appsignal.add_distribution_value('seo.visit_aggregate.batch_duration_seconds', duration)
    Appsignal.increment_counter('seo.visit_aggregate.failures', failures) if failures.positive?
  end

  if failures.positive?
    ErrorReporting.error("SEO visit aggregate batch #{status.bid}: #{failures} day(s) failed")
    return
  end

  SeoVisitsSyncApplyWorker.perform_async(period_end)
end