Skip to content

Commit 1cc3172

Browse files
committed
fix: retry components that error in jekyll due to a thread race
1 parent 02b3436 commit 1cc3172

File tree

1 file changed

+38
-9
lines changed
  • generator-plugins/jekyll/cloudcannon-jekyll-bookshop/lib/cloudcannon-jekyll-bookshop

1 file changed

+38
-9
lines changed

generator-plugins/jekyll/cloudcannon-jekyll-bookshop/lib/cloudcannon-jekyll-bookshop/structures.rb

+38-9
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,47 @@ def self.build_from_location(base_path, site)
5858
Jekyll.logger.info "Bookshop:",
5959
"Parsing Stories from #{base_path}"
6060

61-
threads = []
62-
Dir.glob("**/*.{bookshop}.{toml,tml,tom,tm}", :base => base_path).each do |f|
63-
threads << Thread.new do
64-
raw_file = File.read(base_path + "/" + f)
65-
component = load_component(raw_file)
66-
67-
transform_component(f, component).each do |transformed_component|
68-
add_structure(site.config["_array_structures"], transformed_component)
61+
files = Dir.glob("**/*.{bookshop}.{toml,tml,tom,tm}", :base => base_path);
62+
63+
read_attempts = 0
64+
while files.size > 0 && read_attempts < 5
65+
processing = files.map(&:clone)
66+
files = []
67+
threads = []
68+
processing.each do |f|
69+
threads << Thread.new do
70+
begin
71+
raw_file = File.read(base_path + "/" + f)
72+
component = load_component(raw_file)
73+
74+
transform_component(f, component).each do |transformed_component|
75+
add_structure(site.config["_array_structures"], transformed_component)
76+
end
77+
rescue
78+
Thread.current[:output] = f
79+
end
6980
end
7081
end
82+
threads.each do |t|
83+
t.join
84+
files << t[:output] if t[:output]
85+
end
86+
Jekyll.logger.info "Bookshop:",
87+
"Had trouble reading #{files.size} file(s), retrying" if files.size > 0
88+
read_attempts += 1
89+
end
90+
91+
if files.size > 0
92+
Jekyll.logger.error "Bookshop:",
93+
"❌ Failed to read #{files.size} file(s)"
94+
files.each do |f|
95+
Jekyll.logger.error "Bookshop:",
96+
"❌ Failed to read #{f}"
97+
end
98+
Jekyll.logger.error "Bookshop:",
99+
"❌ Check your TOML files are valid."
100+
exit 1
71101
end
72-
threads.each(&:join)
73102
end
74103

75104
def self.setup_helpers

0 commit comments

Comments
 (0)