Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 88285a9

Browse files
author
Alan Gabbianelli
authored
Add healthcheck endpoint (#740)
Add healthcheck endpoint
2 parents 1e73246 + 1887db8 commit 88285a9

File tree

17 files changed

+273
-84
lines changed

17 files changed

+273
-84
lines changed

.rspec

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
--require spec_helper
1+
--colour
2+
--format=d
3+
--require rails_helper

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ gem 'elasticsearch', '~> 5.0.4'
88
gem 'elasticsearch-model', '~> 5.0.1'
99
gem 'elasticsearch-rails', '~> 5.0.1'
1010
gem 'gds-sso'
11+
gem 'govuk_app_config', '~> 1.16.1'
1112
gem 'govuk_elements_rails'
1213
gem 'govuk_sidekiq', '~> 3.0'
1314
gem 'govuk_template'

Gemfile.lock

+12-6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ GEM
4545
ast (2.4.0)
4646
audited (4.5.0)
4747
activerecord (>= 4.0, < 5.2)
48+
aws-xray-sdk (0.10.2)
49+
oj (~> 3.0)
4850
binding_of_caller (0.7.2)
4951
debug_inspector (>= 0.0.1)
5052
brakeman (4.2.1)
@@ -98,7 +100,7 @@ GEM
98100
factory_bot_rails (4.11.1)
99101
factory_bot (~> 4.11.1)
100102
railties (>= 3.0.0)
101-
faraday (0.12.1)
103+
faraday (0.12.2)
102104
multipart-post (>= 1.2, < 3)
103105
ffi (1.9.23)
104106
fugit (1.1.1)
@@ -126,7 +128,8 @@ GEM
126128
rubocop (~> 0.64)
127129
rubocop-rspec (~> 1.28)
128130
scss_lint
129-
govuk_app_config (1.3.2)
131+
govuk_app_config (1.16.1)
132+
aws-xray-sdk (~> 0.10.0)
130133
logstasher (~> 1.2.2)
131134
sentry-raven (~> 2.7.1)
132135
statsd-ruby (~> 1.4.0)
@@ -208,7 +211,7 @@ GEM
208211
minitest (5.11.3)
209212
multi_json (1.12.1)
210213
multi_xml (0.6.0)
211-
multipart-post (2.0.0)
214+
multipart-post (2.1.0)
212215
netrc (0.11.0)
213216
nio4r (2.3.1)
214217
nokogiri (1.10.1)
@@ -220,6 +223,7 @@ GEM
220223
multi_json (~> 1.3)
221224
multi_xml (~> 0.5)
222225
rack (>= 1.2, < 3)
226+
oj (3.7.12)
223227
omniauth (1.8.1)
224228
hashie (>= 3.4.6, < 3.6.0)
225229
rack (>= 1.6.2, < 3)
@@ -289,7 +293,8 @@ GEM
289293
redis (4.0.1)
290294
redis-namespace (1.6.0)
291295
redis (>= 3.0.4)
292-
request_store (1.3.2)
296+
request_store (1.4.1)
297+
rack (>= 1.4)
293298
rest-client (2.0.2)
294299
http-cookie (>= 1.0.2, < 2.0)
295300
mime-types (>= 1.16, < 4.0)
@@ -345,7 +350,7 @@ GEM
345350
scss_lint (0.57.1)
346351
rake (>= 0.9, < 13)
347352
sass (~> 3.5, >= 3.5.5)
348-
sentry-raven (2.7.1)
353+
sentry-raven (2.7.4)
349354
faraday (>= 0.7.6, < 1.0)
350355
sidekiq (5.1.1)
351356
concurrent-ruby (~> 1.0)
@@ -400,7 +405,7 @@ GEM
400405
unf_ext
401406
unf_ext (0.0.7.5)
402407
unicode-display_width (1.5.0)
403-
unicorn (5.4.0)
408+
unicorn (5.4.1)
404409
kgio (~> 2.6)
405410
raindrops (~> 0.7)
406411
warden (1.2.7)
@@ -439,6 +444,7 @@ DEPENDENCIES
439444
factory_bot_rails (~> 4.0)
440445
gds-sso
441446
govuk-lint (~> 3.11)
447+
govuk_app_config (~> 1.16.1)
442448
govuk_elements_rails
443449
govuk_sidekiq (~> 3.0)
444450
govuk_template
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
module Healthcheck
2+
module RecurringJobs
3+
class PackageSync
4+
include ActionView::Helpers::DateHelper
5+
6+
JOB_NAME = 'ckan_v26_package_sync'.freeze
7+
JOB_FREQUENCY = 10.minutes
8+
WARNING_DELAY = 2.minutes
9+
CRITICAL_DELAY = 1.hour
10+
11+
def name
12+
:package_sync
13+
end
14+
15+
def status
16+
if Time.parse(when_last_run) <= critical_latency
17+
:critical
18+
elsif Time.parse(when_last_run) <= warning_latency
19+
:warning
20+
else
21+
:ok
22+
end
23+
end
24+
25+
def details
26+
{
27+
critical: when_last_run,
28+
warning: when_last_run
29+
}
30+
end
31+
32+
def message
33+
"The job '#{JOB_NAME}' should run every #{distance_of_time_in_words(JOB_FREQUENCY)}. It was last run #{when_last_run}."
34+
end
35+
36+
private
37+
38+
def when_last_run
39+
SidekiqScheduler::RedisManager.get_job_last_time(JOB_NAME)
40+
end
41+
42+
def critical_latency
43+
(JOB_FREQUENCY + CRITICAL_DELAY).ago
44+
end
45+
46+
def warning_latency
47+
(JOB_FREQUENCY + WARNING_DELAY).ago
48+
end
49+
end
50+
end
51+
end

config/routes.rb

+4
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,8 @@
6767
get 'manage/organisation', to: 'manage#manage_organisation'
6868

6969
resource :session, only: %i[new create]
70+
71+
get "/healthcheck", to: GovukHealthcheck.rack_response(
72+
Healthcheck::RecurringJobs::PackageSync.new
73+
)
7074
end

spec/factories/ckan_v26_ckan_org.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
FactoryBot.define do
22
factory :ckan_v26_ckan_org, class: CKAN::V26::CKANOrg do
3-
id SecureRandom.uuid
4-
name "Name"
5-
category "Category"
6-
title "Title"
3+
id { SecureRandom.uuid }
4+
name { "Name" }
5+
category { "Category" }
6+
title { "Title" }
77

8-
add_attribute("contact-name", "Mr. Contact")
9-
add_attribute("contact-email", "[email protected]")
10-
add_attribute("foi-name", "Mr. FOI")
11-
add_attribute("foi-email", "[email protected]")
12-
add_attribute("foi-web", "http://foi.com")
8+
add_attribute("contact-name") { "Mr. Contact" }
9+
add_attribute("contact-email") { "[email protected]" }
10+
add_attribute("foi-name") { "Mr. FOI" }
11+
add_attribute("foi-email") { "[email protected]" }
12+
add_attribute("foi-web") { "http://foi.com" }
1313

1414
initialize_with do
1515
CKAN::V26::CKANOrg.new(attributes.stringify_keys)

spec/factories/ckan_v26_package.rb

+41-39
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,53 @@
11
FactoryBot.define do
22
factory :ckan_v26_package, class: CKAN::V26::Package do
3-
name "Name"
4-
title "Title"
5-
notes "Notes"
6-
metadata_created "2015-10-06T11:21:26.185852"
7-
metadata_updated "2018-06-05T12:40:12.239474"
8-
license_id "uk-ogl"
9-
geographic_coverage %w[england scotland wales]
10-
owner_org SecureRandom.uuid
3+
name { "Name" }
4+
title { "Title" }
5+
notes { "Notes" }
6+
metadata_created { "2015-10-06T11:21:26.185852" }
7+
metadata_updated { "2018-06-05T12:40:12.239474" }
8+
license_id { "uk-ogl" }
9+
geographic_coverage { %w[england scotland wales] }
10+
owner_org { SecureRandom.uuid }
1111

12-
add_attribute("theme-primary", "Environment & Fisheries")
13-
add_attribute("contact-name", "Mr. Contact")
14-
add_attribute("contact-email", "[email protected]")
15-
add_attribute("foi-name", "Mr. FOI")
16-
add_attribute("foi-email", "[email protected]")
17-
add_attribute("foi-web", "http://foi.com")
18-
add_attribute("schema", [{
19-
"url" => "https://github.com/datagovuk/schemas/tree/master/organogram",
20-
"id" => "d3c0b23f-6979-45e4-88ed-d2ab59b005d0",
21-
"title" => "Organisation structure including senior roles & salaries (org chart / organogram for central government departments and agencies)",
22-
}])
12+
add_attribute("theme-primary") { "Environment & Fisheries" }
13+
add_attribute("contact-name") { "Mr. Contact" }
14+
add_attribute("contact-email") { "[email protected]" }
15+
add_attribute("foi-name") { "Mr. FOI" }
16+
add_attribute("foi-email") { "[email protected]" }
17+
add_attribute("foi-web") { "http://foi.com" }
18+
add_attribute("schema") do
19+
[{
20+
"url" => "https://github.com/datagovuk/schemas/tree/master/organogram",
21+
"id" => "d3c0b23f-6979-45e4-88ed-d2ab59b005d0",
22+
"title" => "Organisation structure including senior roles & salaries (org chart / organogram for central government departments and agencies)",
23+
}]
24+
end
2325

2426
extras do
2527
[{ "licence" => "Open Government Licence 3.0 (United Kingdom)" }]
2628
end
2729

2830
trait :inspire do
29-
add_attribute("access_constraints", "[\"There are no public access constraints to this data. Use of this data is subject to the licence identified.\"]")
30-
add_attribute("bbox-east-long", "2.072")
31-
add_attribute("bbox-north-lat", "55.816")
32-
add_attribute("bbox-south-lat", "49.943")
33-
add_attribute("bbox-west-long", "-6.236")
34-
add_attribute("coupled-resource", "[]")
35-
add_attribute("dataset-reference-date", "[{\"type\": \"creation\", \"value\": \"2004-01-01\"}, {\"type\": \"revision\", \"value\": \"2018-04-30\"}]")
36-
add_attribute("frequency-of-update", "quarterly")
37-
add_attribute("harvest_object_id", SecureRandom.uuid)
38-
add_attribute("harvest_source_reference", SecureRandom.uuid)
39-
add_attribute("import_source", "harvest")
40-
add_attribute("metadata-date", "2018-06-05")
41-
add_attribute("metadata-language", "eng")
42-
add_attribute("provider", "")
43-
add_attribute("resource-type", "dataset")
44-
add_attribute("responsible-party", "Environment Agency (pointOfContact)")
45-
add_attribute("spatial", "{\"type\":\"Polygon\",\"coordinates\":[[[2.072, 49.943],[2.072, 55.816], [-6.236, 55.816], [-6.236, 49.943], [2.072, 49.943]]]}")
46-
add_attribute("spatial-data-service-type", "")
47-
add_attribute("spatial-reference-system", "http://www.opengis.net/def/crs/EPSG/0/27700")
48-
add_attribute("guid", SecureRandom.uuid)
31+
add_attribute("access_constraints") { "[\"There are no public access constraints to this data. Use of this data is subject to the licence identified.\"]" }
32+
add_attribute("bbox-east-long") { "2.072" }
33+
add_attribute("bbox-north-lat") { "55.816" }
34+
add_attribute("bbox-south-lat") { "49.943" }
35+
add_attribute("bbox-west-long") { "-6.236" }
36+
add_attribute("coupled-resource") { "[]" }
37+
add_attribute("dataset-reference-date") { "[{\"type\": \"creation\", \"value\": \"2004-01-01\"}, {\"type\": \"revision\", \"value\": \"2018-04-30\"}]" }
38+
add_attribute("frequency-of-update") { "quarterly" }
39+
add_attribute("harvest_object_id") { SecureRandom.uuid }
40+
add_attribute("harvest_source_reference") { SecureRandom.uuid }
41+
add_attribute("import_source") { "harvest" }
42+
add_attribute("metadata-date") { "2018-06-05" }
43+
add_attribute("metadata-language") { "eng" }
44+
add_attribute("provider") { "" }
45+
add_attribute("resource-type") { "dataset" }
46+
add_attribute("responsible-party") { "Environment Agency (pointOfContact)" }
47+
add_attribute("spatial") { "{\"type\":\"Polygon\",\"coordinates\":[[[2.072, 49.943],[2.072, 55.816], [-6.236, 55.816], [-6.236, 49.943], [2.072, 49.943]]]}" }
48+
add_attribute("spatial-data-service-type") { "" }
49+
add_attribute("spatial-reference-system") { "http://www.opengis.net/def/crs/EPSG/0/27700" }
50+
add_attribute("guid") { SecureRandom.uuid }
4951
end
5052

5153
trait :harvested do

spec/factories/ckan_v26_resource.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
FactoryBot.define do
22
factory :ckan_v26_resource, class: CKAN::V26::Resource do
3-
url "http://environment.data.gov.uk/ds/wms?SERVICE=WMS&INTERFACE=ENVIRONMENT--86ec354f-d465-11e4-b09e-f0def148f590&request=GetCapabilities"
4-
format "WMS"
5-
name "Resource locator"
6-
description "Resource locator"
7-
created "2016-04-05T09:48:43.164470"
8-
resource_type "file"
3+
url { "http://environment.data.gov.uk/ds/wms?SERVICE=WMS&INTERFACE=ENVIRONMENT--86ec354f-d465-11e4-b09e-f0def148f590&request=GetCapabilities" }
4+
format { "WMS" }
5+
name { "Resource locator" }
6+
description { "Resource locator" }
7+
created { "2016-04-05T09:48:43.164470" }
8+
resource_type { "file" }
99

1010
initialize_with do
1111
CKAN::V26::Resource.new(attributes.stringify_keys)

spec/factories/datafile.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
FactoryBot.define do
22
factory :datafile do
33
dataset
4-
url 'http://google.com'
5-
name 'My Datafile'
6-
format 'CSV'
7-
start_date 1.month.ago
8-
end_date 1.week.ago
9-
type 'Datafile'
4+
url { 'http://google.com' }
5+
name { 'My Datafile' }
6+
format { 'CSV' }
7+
start_date { 1.month.ago }
8+
end_date { 1.week.ago }
9+
type { 'Datafile' }
1010
end
1111
end

spec/factories/dataset.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
FactoryBot.define do
22
factory :dataset do
33
organisation
4-
title "Price paid for dragon glass"
5-
summary "All transactions for dragon glass"
6-
legacy_name "ye-olde-slug"
7-
location1 "Westeros"
8-
frequency "never"
9-
licence_code "uk-ogl"
4+
title { "Price paid for dragon glass" }
5+
summary { "All transactions for dragon glass" }
6+
legacy_name { "ye-olde-slug" }
7+
location1 { "Westeros" }
8+
frequency { "never" }
9+
licence_code { "uk-ogl" }
1010
topic
11-
status "published"
11+
status { "published" }
1212

1313
after(:create) do |dataset, _|
1414
dataset.publish if dataset.published? # Make sure it's in Elasticsearch

spec/factories/doc.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FactoryBot.define do
22
factory :doc do
33
dataset
4-
url 'http://google.com'
5-
name 'My Doc'
4+
url { 'http://google.com' }
5+
name { 'My Doc' }
66
end
77
end

spec/factories/link.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FactoryBot.define do
22
factory :link do
33
dataset
4-
url 'http://google.com'
5-
name 'My link'
4+
url { 'http://google.com' }
5+
name { 'My link' }
66
end
77
end

spec/factories/organisation.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FactoryBot.define do
22
factory :organisation do
3-
name "land-registry"
4-
title "Land Registry"
3+
name { "land-registry" }
4+
title { "Land Registry" }
55
govuk_content_id { SecureRandom.uuid }
66
end
77
end

spec/factories/topic.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FactoryBot.define do
22
factory :topic do
3-
name "business-and-economy"
4-
title "Business and Economy"
3+
name { "business-and-economy" }
4+
title { "Business and Economy" }
55
end
66
end

spec/factories/user.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FactoryBot.define do
22
factory :user do
3-
4-
name 'Test User'
3+
email { '[email protected]' }
4+
name { 'Test User' }
55
organisation_content_id { SecureRandom.uuid }
66
end
77
end

0 commit comments

Comments
 (0)