gnodet-bot commented on code in PR #28778:
URL: https://github.com/apache/camel/pull/28778#discussion_r4433327910
##########
dsl/camel-jbang/camel-launcher/src/main/java/org/apache/camel/dsl/jbang/launcher/selfupdate/UpdateChecker.java:
##########
@@ -156,22 +181,32 @@ private static Properties readCache(Path cacheFile) {
return props;
}
- // Runs on a daemon thread; any failure (network, timeout, parse) is
swallowed, but last_checked is still
- // updated so a persistent failure doesn't retry on every single
invocation.
- private static void refreshCache(Path cacheFile, Pin pin) {
+ // Writes last_checked (and the target) before the fetch, so that a
persistent failure, or a fetch that the JVM
+ // stops, doesn't retry on every single invocation.
+ private static Properties markChecked(Path cacheFile, String target) {
Properties props = readCache(cacheFile);
- String target = targetOf(pin);
if (!target.equals(props.getProperty(TARGET_KEY, LATEST_TARGET))) {
// The cached version was resolved for another target (the pin
changed): never compare against it.
props.remove("latest_version");
}
props.setProperty(TARGET_KEY, target);
props.setProperty("last_checked",
Long.toString(System.currentTimeMillis()));
- try {
- props.setProperty("latest_version",
resolve(ManifestFetcher.fromEnvironment(), pin));
+ writeCache(cacheFile, props);
+ return props;
+ }
+
+ // Runs on a daemon thread; any failure (network, timeout, parse) is
swallowed, keeping whatever latest_version (if
+ // any) was already cached.
+ private static void refreshCache(Path cacheFile, Properties props, Pin
pin) {
+ try (ManifestFetcher fetcher = ManifestFetcher.fromEnvironment()) {
+ props.setProperty("latest_version", resolve(fetcher, pin));
} catch (Exception e) {
- // Network/timeout/parse failure: keep whatever latest_version (if
any) was already cached.
+ return;
Review Comment:
The old code had an inline comment in the catch body explaining the intent.
The method-level comment above `refreshCache` does say "any failure... is
swallowed", but a reader scanning the method body won't see it from here.
Consider restoring a brief comment:
```suggestion
// network/parse failure: last_checked was already written by
markChecked, so the next run won't retry
return;
```
--
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]