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

Commit 65afd6f

Browse files
authored
Merge pull request #1104 from alphagov/ruby-2-7-5
Upgrade Ruby to 2.7.5
2 parents 9ee87cd + e7104e6 commit 65afd6f

File tree

3 files changed

+47
-46
lines changed

3 files changed

+47
-46
lines changed

.ruby-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.7.2
1+
2.7.5

Dockerfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# This Dockerfile is used with the docker-ckan dev stack
2-
FROM ruby:2.7.2
1+
FROM ruby:2.7.5
32

43
WORKDIR /srv/app/datagovuk_publish
54

app/lib/ckan/v26/depaginator.rb

+45-43
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ module CKAN
22
module V26
33
class Depaginator
44
include CKAN::Modules::URLBuilder
5-
# temp increase to 10000, should normally be 100
6-
MAX_DELETIONS = 10_000
5+
MAX_DELETIONS = 100
76

87
def self.depaginate(*args, **kwargs)
98
new(*args, **kwargs).depaginate
@@ -18,60 +17,63 @@ def initialize(base_url, existing_total:)
1817
def depaginate
1918
loop do
2019
url = append_url(base_url, params: { "start" => results.count })
20+
begin
21+
raw_response = url.read
22+
response = JSON.parse(raw_response)
23+
result = response.fetch("result")
24+
page = result.fetch("results")
25+
total_expected = result.fetch("count")
26+
total_expected_from_first_response ||= total_expected
27+
28+
if total_expected != total_expected_from_first_response
29+
raise ExpectedTotalChangedError, <<~MESSAGE
30+
New expected count `#{total_expected}` from CKAN does not match
31+
the original expected count of `#{total_expected_from_first_response}`.
2132
22-
raw_response = url.read
23-
response = JSON.parse(raw_response)
24-
result = response.fetch("result")
25-
page = result.fetch("results")
26-
total_expected = result.fetch("count")
27-
total_expected_from_first_response ||= total_expected
28-
29-
if total_expected != total_expected_from_first_response
30-
raise ExpectedTotalChangedError, <<~MESSAGE
31-
New expected count `#{total_expected}` from CKAN does not match
32-
the original expected count of `#{total_expected_from_first_response}`.
33-
34-
CKAN response:
35-
#{raw_response}
36-
MESSAGE
37-
end
33+
CKAN response:
34+
#{raw_response}
35+
MESSAGE
36+
end
3837

39-
results.concat(page)
38+
results.concat(page)
4039

41-
if results.count > total_expected
42-
raise MoreResultsThanExpectedError, <<~MESSAGE
43-
We have received more results (#{results.count}) than expected (#{total_expected}).
40+
if results.count > total_expected
41+
raise MoreResultsThanExpectedError, <<~MESSAGE
42+
We have received more results (#{results.count}) than expected (#{total_expected}).
4443
45-
CKAN response:
46-
#{raw_response}
47-
MESSAGE
48-
end
44+
CKAN response:
45+
#{raw_response}
46+
MESSAGE
47+
end
4948

50-
if page.empty?
51-
if results.count == total_expected
52-
number_being_deleted = existing_total - results.count
49+
if page.empty?
50+
if results.count == total_expected
51+
number_being_deleted = existing_total - results.count
5352

54-
if number_being_deleted <= MAX_DELETIONS
55-
break
56-
else
57-
raise DeletionTooLargeError, <<~MESSAGE
58-
Attempting to delete `#{number_being_deleted}` datasets.
53+
if number_being_deleted <= MAX_DELETIONS
54+
break
55+
else
56+
raise DeletionTooLargeError, <<~MESSAGE
57+
Attempting to delete `#{number_being_deleted}` datasets.
5958
60-
No more than #{MAX_DELETIONS} datasets can be deleted at once.
59+
No more than #{MAX_DELETIONS} datasets can be deleted at once.
60+
61+
CKAN response:
62+
#{raw_response}
63+
MESSAGE
64+
end
65+
else
66+
raise EarlyEmptyPageError, <<~MESSAGE
67+
We have received an empty page but have only received `#{results.count}`
68+
results rather than the expected `#{total_expected}` results.
6169
6270
CKAN response:
6371
#{raw_response}
6472
MESSAGE
6573
end
66-
else
67-
raise EarlyEmptyPageError, <<~MESSAGE
68-
We have received an empty page but have only received `#{results.count}`
69-
results rather than the expected `#{total_expected}` results.
70-
71-
CKAN response:
72-
#{raw_response}
73-
MESSAGE
7474
end
75+
rescue OpenURI::HTTPError
76+
logger.error "Problem getting response from #{url}"
7577
end
7678
end
7779

0 commit comments

Comments
 (0)