Skip to content

Commit

Permalink
Retry writing compiled schema files.
Browse files Browse the repository at this point in the history
Signed-off-by: Hermann Mayer <[email protected]>
  • Loading branch information
Jack12816 committed Apr 26, 2024
1 parent 9ea4320 commit 0eb62b5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### next

* TODO: Replace this bullet point with an actual description of a change.
* Added a retry to write compiled schema files as this may fail on parallel
execution (#33)

### 1.5.0

Expand Down
1 change: 1 addition & 0 deletions lib/rimless.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require 'karafka'
require 'karafka-sidekiq-backend'
require 'sparsify'
require 'retries'
require 'erb'

# The top level namespace for the rimless gem.
Expand Down
13 changes: 9 additions & 4 deletions lib/rimless/avro_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ def recompile_schemas
def render_file(src)
# Convert the template path to the destination path
dest = schema_path(src)
# Create the deep path when not yet existing
FileUtils.mkdir_p(File.dirname(dest))
# Write the rendered file contents to the destination
File.write(dest, ERB.new(File.read(src)).result(binding))

# Allow parallel cleanups and execution
with_retries(max_tries: 3, rescue: Errno::ENOENT) do
# Create the deep path when not yet existing
FileUtils.mkdir_p(File.dirname(dest))
# Write the rendered file contents to the destination
File.write(dest, ERB.new(File.read(src)).result(binding))
end

# Check the written file for correct JSON
validate_file(dest)
end
Expand Down
1 change: 1 addition & 0 deletions rimless.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'karafka', '~> 1.4', '< 1.4.15'
spec.add_runtime_dependency 'karafka-sidekiq-backend', '~> 1.4'
spec.add_runtime_dependency 'karafka-testing', '~> 1.4'
spec.add_runtime_dependency 'retries', '>= 0.0.5'
spec.add_runtime_dependency 'sinatra', '~> 2.2'
spec.add_runtime_dependency 'sparsify', '~> 1.1'
spec.add_runtime_dependency 'waterdrop', '~> 1.4'
Expand Down

0 comments on commit 0eb62b5

Please sign in to comment.