-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1522 from alphagov/bulk-data-cache-nov
Load government data in an asynchronous task
- Loading branch information
Showing
51 changed files
with
929 additions
and
590 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class PopulateBulkDataJob < ApplicationJob | ||
retry_on BulkData::RemoteDataUnavailableError do |_job, error| | ||
GovukError.notify(error) unless error.cause.is_a?(GdsApi::HTTPServerError) | ||
end | ||
|
||
def perform | ||
run_exclusively do | ||
BulkData::GovernmentRepository.new.populate_cache(older_than: 5.minutes.ago) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
class Government | ||
include ActiveModel::Model | ||
include InitializeWithHash | ||
|
||
def self.find(content_id) | ||
government = all.find { |g| g.content_id == content_id } | ||
government || (raise "Government #{content_id} not found") | ||
end | ||
|
||
def self.for_date(date) | ||
all.find { |government| government.covers?(date) } if date | ||
end | ||
|
||
def self.current | ||
for_date(Date.current) | ||
end | ||
|
||
def self.past | ||
all.reject(&:current?) | ||
end | ||
|
||
def self.all | ||
@all ||= YAML.load_file(Rails.root.join("config/governments.yml")) | ||
.map { |hash| new(hash) } | ||
end | ||
|
||
attr_accessor :content_id, :slug, :name, :start_date, :end_date | ||
attr_accessor :content_id, :locale, :title, :details | ||
|
||
def ==(other) | ||
content_id == other.content_id | ||
content_id == other.content_id && locale == other.locale | ||
end | ||
|
||
alias_method :eql?, :== | ||
|
||
def covers?(date) | ||
return false if date < start_date | ||
return false if date < started_on | ||
# Most end dates in Whitehall are the last date of a government so we | ||
# treat the date as going up to 23:59:59 on the day by appending 1 day to | ||
# the date | ||
return false if end_date && date >= (end_date + 1) | ||
return false if ended_on && date >= (ended_on + 1) | ||
|
||
true | ||
end | ||
|
||
def started_on | ||
@started_on ||= Date.parse(details["started_on"]) | ||
end | ||
|
||
def ended_on | ||
@ended_on ||= Date.parse(details["ended_on"]) if details["ended_on"] | ||
end | ||
|
||
def current? | ||
self == self.class.current | ||
details["current"] == true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
<%= render "govuk_publishing_components/components/notice", | ||
{ | ||
title: I18n.t( | ||
"documents.show.historical.title", | ||
document_type: @edition.document_type.label.downcase | ||
), | ||
description_text: I18n.t( | ||
"documents.show.historical.description", | ||
government_name: @edition.government.name | ||
), | ||
title: t("documents.show.historical.title", | ||
document_type: @edition.document_type.label.downcase), | ||
description_text: t("documents.show.historical.description", | ||
government_name: @edition.government.title), | ||
} | ||
%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<% if Rails.env.development? %> | ||
<% | ||
title = "Expected cached data missing" | ||
backtrace = error.backtrace.map { |line| "- <code>#{line}</code>" }.join("\n") | ||
body_govspeak = <<~GOVSPEAK | ||
Content Publisher relies on background jobs to load data from other GOV.UK | ||
applications. To resolve this error ensure that the worker process is | ||
running for Content Publisher. | ||
|
||
Alternatively or if you are experiencing issues with the worker, you can | ||
run the job directly in a rails console which should tell you more: | ||
`PopulateBulkDataJob.perform_now`. | ||
|
||
## Backtrace | ||
|
||
#{backtrace} | ||
GOVSPEAK | ||
%> | ||
<%= render partial: "errors/error", locals: { title: title, body_govspeak: body_govspeak } %> | ||
<% else %> | ||
<%= render partial: "errors/error", locals: t("errors.local_data_unavailable") %> | ||
<% end %> |
Oops, something went wrong.