Skip to content

Commit c48c878

Browse files
authored
Merge pull request #364 from openstax/more_slugs
Improve handling of archive versions missing certain books
2 parents 689d631 + cd41eb2 commit c48c878

File tree

3 files changed

+35808
-115720
lines changed

3 files changed

+35808
-115720
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ GEM
318318
roar
319319
roar-rails (>= 1)
320320
uber
321-
openstax_content (1.1.0)
321+
openstax_content (1.2.0)
322322
aws-sdk-s3
323323
faraday
324324
nokogiri

lib/content.rb

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,43 @@ def self.slugs_by_page_uuid
66
"slugs_by_page_uuid/#{OpenStax::Content::Abl.new.digest}"
77
) do
88
{}.tap do |hash|
9-
OpenStax::Content::Abl.new.approved_books.each do |book|
10-
begin
11-
pages = book.all_pages
12-
rescue StandardError => exception
13-
# Sometimes books in the ABL fail to load
14-
# Log it, but keep going
15-
Rails.logger.error exception
16-
else
17-
pages.each do |page|
18-
hash[page.uuid] ||= []
19-
hash[page.uuid] << { book: book.slug, page: page.slug }
9+
books = OpenStax::Content::Abl.new.approved_books
10+
11+
until books.empty?
12+
previous_version = nil
13+
previous_archive = nil
14+
retry_books = []
15+
16+
books.each do |book|
17+
begin
18+
pages = book.all_pages
19+
rescue StandardError => exception
20+
# Sometimes books in the ABL fail to load
21+
# Retry with an earlier version of archive, if possible
22+
previous_version ||= book.archive.previous_version
23+
24+
if previous_version.nil?
25+
raise exception
26+
else
27+
previous_archive ||= OpenStax::Content::Archive.new version: previous_version
28+
29+
retry_books << OpenStax::Content::Book.new(
30+
archive: previous_archive,
31+
uuid: book.uuid,
32+
version: book.version,
33+
slug: book.slug,
34+
style: book.style
35+
)
36+
end
37+
else
38+
pages.each do |page|
39+
hash[page.uuid] ||= []
40+
hash[page.uuid] << { book: book.slug, page: page.slug }
41+
end
2042
end
2143
end
44+
45+
books = retry_books
2246
end
2347
end
2448
end

spec/cassettes/Exercise/automatically_sets_slug_tags.yml

Lines changed: 35772 additions & 115708 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)