Skip to content

Commit

Permalink
Feature/automate reindexing (#206)
Browse files Browse the repository at this point in the history
* SRCH-126 - Automate reindexing
  • Loading branch information
peggles2 authored Dec 19, 2018
1 parent 1d025d5 commit 7a7e7bb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/models/searchgov_url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ class SearchgovUrl < ActiveRecord::Base
scope :fetch_required, -> do
where('last_crawled_at IS NULL
OR lastmod > last_crawled_at
OR enqueued_for_reindex')
OR enqueued_for_reindex
OR (last_crawl_status = "OK" AND last_crawled_at < ?)', 1.month.ago).
order(last_crawled_at: :ASC)
end

class SearchgovUrlError < StandardError; end
Expand Down
5 changes: 5 additions & 0 deletions spec/fixtures/searchgov_urls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ enqueued:
last_crawled_at: <%= 1.day.ago.to_s(:db) %>
lastmod: <%= 1.week.ago.to_s(:db) %>
enqueued_for_reindex: true

crawled_more_than_month:
url: http://www.agency.gov/crawled_more_than_month
last_crawled_at: <%= 45.days.ago.to_s(:db) %>
last_crawl_status: 'OK'
5 changes: 5 additions & 0 deletions spec/models/searchgov_url_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
expect(SearchgovUrl.fetch_required.pluck(:url)).
to include 'http://www.agency.gov/enqueued'
end

it 'includes urls last crawled more than 30 days and crawl status is ok' do
expect(SearchgovUrl.fetch_required.pluck(:url)).
to include 'http://www.agency.gov/crawled_more_than_month'
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/support/fetchable_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
describe '.ok' do
it 'includes successfully fetched records' do
expect(described_class.ok.pluck(:url)).
to match_array ['http://agency.gov/ok']
to include 'http://agency.gov/ok'
end
end

Expand Down

0 comments on commit 7a7e7bb

Please sign in to comment.