This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
The following commit(s) were added to refs/heads/master by this push:
new e8e637a3 Add retry for html rendering
e8e637a3 is described below
commit e8e637a3248152a2b1a392651fcdafa96f4eee01
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Thu Dec 7 16:27:46 2023 +0100
Add retry for html rendering
---
.../org/apache/sling/offline/impl/Starter.java | 42 +++++++++++++++-------
1 file changed, 30 insertions(+), 12 deletions(-)
diff --git
a/org.apache.sling.offline/src/main/java/org/apache/sling/offline/impl/Starter.java
b/org.apache.sling.offline/src/main/java/org/apache/sling/offline/impl/Starter.java
index 3b59781d..8c10f775 100644
---
a/org.apache.sling.offline/src/main/java/org/apache/sling/offline/impl/Starter.java
+++
b/org.apache.sling.offline/src/main/java/org/apache/sling/offline/impl/Starter.java
@@ -75,7 +75,8 @@ public class Starter {
return r.getName().endsWith(".md");
}
- private void process(final ResourceResolver resolver, final Resource
resource) throws IOException, ServletException {
+ private void process(final ResourceResolver resolver, final Resource
resource, final boolean retry)
+ throws IOException, ServletException {
if ( this.ignore(resource) ) {
return;
}
@@ -83,16 +84,31 @@ public class Starter {
return;
}
logger.info("Processing {}", resource.getPath());
- final SlingHttpServletRequest req =
Builders.newRequestBuilder(resource)
- .withExtension("html")
- .build();
- final SlingHttpServletResponseResult resp =
Builders.newResponseBuilder().build();
- processor.processRequest(req, resp, resolver);
-
- final File output = new File(config.output_path(),
resource.getPath().substring(this.config.input_path().length()).concat(".html"));
- logger.info("Writing output to {}", output.getAbsolutePath());
- output.getParentFile().mkdirs();
- Files.writeString(output.toPath(), resp.getOutputAsString());
+ final long endAt = System.currentTimeMillis() + 5000;
+ while ( System.currentTimeMillis() < endAt ) {
+ final SlingHttpServletRequest req =
Builders.newRequestBuilder(resource)
+ .withExtension("html")
+ .build();
+ final SlingHttpServletResponseResult resp =
Builders.newResponseBuilder().build();
+ processor.processRequest(req, resp, resolver);
+
+ if ( resp.getStatus() == 200 ) {
+ final File output = new File(config.output_path(),
resource.getPath().substring(this.config.input_path().length()).concat(".html"));
+ logger.info("Writing output to {}", output.getAbsolutePath());
+ output.getParentFile().mkdirs();
+ Files.writeString(output.toPath(), resp.getOutputAsString());
+ return;
+ }
+ if (!retry) {
+ break;
+ }
+ try {
+ Thread.sleep(100);
+ } catch ( final InterruptedException ie) {
+ // ignore
+ }
+ }
+ logger.error("Unable to create html for {}", resource.getPath());
}
private Resource getResource(final ResourceResolver resolver, final String
path) {
@@ -121,8 +137,10 @@ public class Starter {
if ( root == null ) {
logger.error("Unable to find root resource at {}",
config.input_path());
} else {
+ boolean first = true;
for(final Resource c : root.getChildren()) {
- process(resolver, c);
+ process(resolver, c, first);
+ first = false;
}
}
} catch ( final Exception e ) {