Class: SeoVisitsSyncApplyWorker

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

Overview

Fans the bounded SiteMap write phase into retryable 500-page jobs after daily
aggregate coverage is complete.

Constant Summary collapse

BATCH_SIZE =

Constant.

Seo::VisitsSyncService::BATCH_SIZE

Instance Method Summary collapse

Instance Method Details

#perform(period_end = Date.current.to_s) ⇒ Object

Runs the job.

Parameters:

  • period_end (Date) (defaults to: Date.current.to_s)

    the period end

Returns:

  • (Object)

    the result



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

def perform(period_end = Date.current.to_s)
  scope = SiteMap.where.not(path: [nil, ''])
  page_count = scope.count
  batch = Sidekiq::Batch.new
  batch.description = "Apply SEO visit counts through #{period_end}"
  batch.on(
    :complete,
    SeoVisitsSyncFinalizer,
    'period_end' => period_end,
    'started_at' => Time.current.iso8601,
    'page_count' => page_count
  )
  batch.jobs do
    scope.in_batches(of: BATCH_SIZE) do |site_maps|
      SeoVisitsSyncBatchWorker.perform_async(site_maps.ids, period_end)
    end
  end

  Rails.event.notify(
    'seo.visit_sync', action: 'apply_dispatched', batch_id: batch.bid, page_count:, period_end:
  )
  batch.bid
end