Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/jobs/click_counter_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class ClickCounterJob < ApplicationJob
queue_as :searchgov

def perform(domain:)
ClickCounter.new(domain: domain).update_click_counts
def perform(domain:, index_name: nil)
ClickCounter.new(domain: domain, index_name: index_name).update_click_counts
end
end
12 changes: 12 additions & 0 deletions app/jobs/click_monitor_spider_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

# Enqueues a ClickCounterJob for each SearchgovDomain in spider
class ClickMonitorSpiderJob < ApplicationJob
queue_as :searchgov

def perform
SearchgovDomain.find_each do |searchgov_domain|
ClickCounterJob.perform_later(domain: searchgov_domain.domain, index_name: ENV.fetch('SEARCHELASTIC_INDEX'))
end
end
end
4 changes: 3 additions & 1 deletion app/services/click_counter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
class ClickCounter
attr_reader :domain

def initialize(domain:)
def initialize(domain:, index_name: nil)
@domain = domain
@index_name = index_name
end

def update_click_counts
Expand All @@ -33,6 +34,7 @@ def statistically_significant_clicks
def update_click_count(url:, count:)
searchgov_url = SearchgovUrl.find_by!(url: url)
I14yDocument.update(document_id: searchgov_url.document_id,
index_name: @index_name,
click_count: count,
handle: 'searchgov')
rescue ActiveRecord::RecordNotFound
Expand Down
2 changes: 2 additions & 0 deletions config/resque_schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ production:
cron: "0 */4 * * *"
ClickMonitorJob:
cron: "0 7 * * 0"
ClickMonitorSpiderJob:
cron: "0 7 * * 6"
20 changes: 20 additions & 0 deletions spec/jobs/click_monitor_spider_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'spec_helper'

describe ClickMonitorSpiderJob do
subject(:job) { described_class.new }

let(:searchgov_domain) do
instance_double(SearchgovDomain, domain: 'nasa.gov')
end

before do
allow(SearchgovDomain).to receive(:find_each).and_yield(searchgov_domain)
end

it_behaves_like 'a searchgov job'

it 'enqueues ClickCounterJobs for each SearchgovDomain' do
expect { job.perform_now }.to have_enqueued_job(ClickCounterJob)
.with(domain: searchgov_domain.domain, index_name: ENV.fetch('SEARCHELASTIC_INDEX'))
end
end