gnodet-bot commented on code in PR #28150:
URL: https://github.com/apache/camel/pull/28150#discussion_r4323749926


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/AuthoringTools.java:
##########
@@ -2271,6 +2294,91 @@ static int integer(Map<String, String> args, String key, 
int defaultValue) {
         }
     }
 
+    /**
+     * Marks the failed exchanges of an earlier version of the routes: those 
that failed before the newest reload of the
+     * routes in the log. The errors are kept until the integration restarts, 
and an agent that read them after a change
+     * took them for errors of its new version, and changed routes that 
already worked.
+     */
+    static JsonObject markBeforeLastReload(JsonObject errors, long pid, String 
name) {
+        try {
+            JsonObject log = LogFileReader.read(pid, name, 1, 
ReloadOutcome.RELOADED, null);
+            if (log.get("lines") instanceof List<?> lines && !lines.isEmpty() 
&& lines.get(0) instanceof JsonObject reload) {
+                return markBefore(errors, reload.getString("time"), 
LocalDateTime.now());
+            }
+        } catch (Exception e) {
+            // no log to tell: the errors as they are
+        }
+        return errors;
+    }
+
+    private static final long RELOAD_MARGIN_MILLIS = 1000;
+
+    /** Marks the errors that failed before the reload at the given time of 
day; the log keeps the time of day only. */
+    static JsonObject markBefore(JsonObject errors, String reloadTime, 
LocalDateTime now) {
+        LocalTime time;
+        try {
+            time = LocalTime.parse(reloadTime);
+        } catch (Exception e) {
+            return errors;
+        }
+        LocalDateTime reload = now.toLocalDate().atTime(time);
+        if (reload.isAfter(now)) {
+            reload = reload.minusDays(1);
+        }
+        // the summary is logged after the new routes started: a margin keeps 
a route that fails at once unmarked
+        long reloadMillis = 
reload.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() - 
RELOAD_MARGIN_MILLIS;

Review Comment:
   Test comment at atZone line



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to