openstax_content 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 640f5b30f23af9597543e0e6239b3def597b456ae05b85c9657e6380d5ad6623
4
- data.tar.gz: ba19461ea0e3700f2f8c752c4dcf2fe5808bf8a798b22707fec47d9857f081c8
3
+ metadata.gz: 3172a1f7fe5b47aa50f602f78991ee47d9ee4f6861e02e5becf8eb5077c83c30
4
+ data.tar.gz: d88d0221599583018bf2eba76e4781523c5855261d8c3f61d751c50d48620b85
5
5
  SHA512:
6
- metadata.gz: a5589b01cfa98a740916cd47274171ada0265429960ca68657124f1d0c6c98e551542b3027db5278845e3ef10b9191d54b74d84cf4fd8db7355c28f2e3722d5e
7
- data.tar.gz: 0e02160d69f9789030a33bd0f84da38eb0922bf3bb06c54fcc6740bdb7649ae1bbd72c62f130ce3e49947f73a711d477380c3e6eb36fc2b40c6a10ba0b344d58
6
+ metadata.gz: d41858c0fe490b46d3d441daa2a98294aa8262fa73c1ea703ccf136cc3fa233f50d470259de4a2186a60c50e5a3f0fe2282b97903182c5b5b4c9972d61bb7ee8
7
+ data.tar.gz: 12beea979dd0a43e019e88be1c0b53c940f8b6683d59ac3c74f42e0bbd9456cdb6824bdd75d60572787aeba3492acdfb918975d46aa1f9218f624b50bdcf437b
@@ -6,8 +6,11 @@ class OpenStax::Content::Abl
6
6
  # If there are more than this number of archive versions still building, errors will happen
7
7
  DEFAULT_MAX_ARCHIVE_ATTEMPTS = 5
8
8
 
9
+ attr_reader :partial_data
10
+
9
11
  def initialize(url: nil)
10
12
  @url = url
13
+ @partial_data = false
11
14
  end
12
15
 
13
16
  def url
@@ -39,35 +42,34 @@ class OpenStax::Content::Abl
39
42
  end
40
43
  end
41
44
 
42
- def each_book_with_previous_archive_version_fallback(max_attempts: DEFAULT_MAX_ARCHIVE_ATTEMPTS, &block)
45
+ def each_book_with_previous_archive_version_fallback(max_attempts: DEFAULT_MAX_ARCHIVE_ATTEMPTS, allow_partial_data: true, &block)
43
46
  raise ArgumentError, 'no block given' if block.nil?
44
47
  raise ArgumentError, 'given block must accept the book as its first argument' if block.arity == 0
45
48
 
46
49
  books = OpenStax::Content::Abl.new.books
47
- attempt = 1
50
+ @partial_data = false
48
51
 
49
- until books.empty?
52
+ books.each do |book|
53
+ attempt = 1
50
54
  previous_version = nil
51
55
  previous_archive = nil
52
- retry_books = []
53
-
54
- books.each do |book|
56
+ while attempt <= max_attempts
55
57
  begin
56
58
  block.call book
59
+ break
57
60
  rescue StandardError => exception
58
- raise exception if attempt >= max_attempts
59
-
60
- # Sometimes books in the latest archive fails to load (when the new version is still building)
61
- # Retry with an earlier version of archive, if possible
62
- previous_version ||= book.archive.previous_version
63
-
64
- if previous_version.nil?
65
- # There are no more earlier archive versions
66
- raise exception
61
+ previous_version = book.archive.previous_version
62
+ if previous_version.nil? || attempt >= max_attempts
63
+ raise exception unless allow_partial_data
64
+ @partial_data = true
65
+ OpenStax::Content::logger.warn do
66
+ "Failed to process book: #{book.uuid}. " \
67
+ "Error: #{exception.class}: #{exception.message}"
68
+ end
69
+ break
67
70
  else
68
- previous_archive ||= OpenStax::Content::Archive.new version: previous_version
69
-
70
- retry_book = OpenStax::Content::Book.new(
71
+ previous_archive = OpenStax::Content::Archive.new version: previous_version
72
+ book = OpenStax::Content::Book.new(
71
73
  archive: previous_archive,
72
74
  uuid: book.uuid,
73
75
  version: book.version,
@@ -75,15 +77,21 @@ class OpenStax::Content::Abl
75
77
  min_code_version: book.min_code_version,
76
78
  committed_at: book.committed_at
77
79
  )
78
-
79
- # If the book requires an archive version that hasn't finished building yet, don't include it
80
- retry_books << retry_book if retry_book.valid?
80
+ # NOTE: This assumes that subsequent archive versions are invalid
81
+ # after finding one invalid archive versions
82
+ unless book.valid?
83
+ raise exception unless allow_partial_data
84
+ @partial_data = true
85
+ OpenStax::Content::logger.warn do
86
+ "Failed to process book: #{book.uuid}. " \
87
+ "Error: invalid book for archive version #{previous_version}"
88
+ end
89
+ break
90
+ end
81
91
  end
92
+ attempt += 1
82
93
  end
83
94
  end
84
-
85
- books = retry_books
86
- attempt += 1
87
95
  end
88
96
  end
89
97
 
@@ -1,5 +1,5 @@
1
1
  module OpenStax
2
2
  module Content
3
- VERSION = '1.5.0'
3
+ VERSION = '1.6.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstax_content
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dante Soares
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-05-02 00:00:00.000000000 Z
11
+ date: 2026-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-s3
@@ -183,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
183
  - !ruby/object:Gem::Version
184
184
  version: '0'
185
185
  requirements: []
186
- rubygems_version: 3.5.21
186
+ rubygems_version: 3.3.7
187
187
  signing_key:
188
188
  specification_version: 4
189
189
  summary: Ruby bindings to read and parse the OpenStax ABL and the content archive