Added revalidate_policy config.

This allows resources to be validated prior to every app launch instead of just
after update.

Also fixed some erroneous logging.
This commit is contained in:
Michael Bayne
2019-05-29 11:40:36 -07:00
parent a4cef568b1
commit 9d6088ab80
4 changed files with 40 additions and 19 deletions
+5
View File
@@ -18,6 +18,11 @@
without a proxy, it does so for that session, but retains the proxy config for future sessions in
which the proxy may again be needed.
* Added `revalidate_policy` config to control when Getdown revalidates resources (by hashing them
and comparing that hash to the values in `digest.txt`). The default, `after_update`, only
validates resources after the app is updated. A new mode, `always`, validates resources prior to
every application launch.
## 1.8.4 - May 14, 2019
* Added `verify_timeout` config to allow customization of the default (60 second) timeout during
@@ -636,21 +636,18 @@ public class Application
}
}
// determine whether we want strict comments
// read some miscellaneous configurations
_strictComments = config.getBoolean("strict_comments");
// determine whether we want to allow offline operation (defaults to false)
_allowOffline = config.getBoolean("allow_offline");
_revalidatePolicy = config.getEnum(
"revalidate_policy", RevalidatePolicy.class, RevalidatePolicy.AFTER_UPDATE);
int tpSize = SysProps.threadPoolSize();
_maxConcDownloads = Math.max(1, config.getInt("max_concurrent_downloads", tpSize));
_verifyTimeout = config.getInt("verify_timeout", 60);
// whether to cache code resources and launch from cache
_useCodeCache = config.getBoolean("use_code_cache");
_codeCacheRetentionDays = config.getInt("code_cache_retention_days", 7);
// maximum simultaneous downloads
_maxConcDownloads = Math.max(1, config.getInt("max_concurrent_downloads",
SysProps.threadPoolSize()));
_verifyTimeout = config.getInt("verify_timeout", 60);
}
/**
@@ -1361,14 +1358,14 @@ public class Application
unpacked.addAll(unpackedAsync);
long complete = System.currentTimeMillis();
log.info("Verified resources", "count", rsrcs.size(), "size", (totalSize/1024) + "k",
"duration", (complete-start) + "ms");
log.info("Verified resources", "count", rsrcs.size(), "alreadyValid", alreadyValid[0],
"size", (totalSize/1024) + "k", "duration", (complete-start) + "ms");
}
private void verifyResource (Resource rsrc, ProgressObserver obs, int[] alreadyValid,
Set<Resource> unpacked,
Set<Resource> toInstall, Set<Resource> toDownload) {
if (rsrc.isMarkedValid()) {
if (_revalidatePolicy != RevalidatePolicy.ALWAYS && rsrc.isMarkedValid()) {
if (alreadyValid != null) {
alreadyValid[0]++;
}
@@ -1765,6 +1762,7 @@ public class Application
protected int _verifyTimeout = 60;
protected RevalidatePolicy _revalidatePolicy = RevalidatePolicy.AFTER_UPDATE;
protected boolean _useCodeCache;
protected int _codeCacheRetentionDays;
@@ -1790,4 +1788,6 @@ public class Application
protected static final String ENV_VAR_PREFIX = "%ENV.";
protected static final Pattern ENV_VAR_PATTERN = Pattern.compile("%ENV\\.(.*?)%");
protected static enum RevalidatePolicy { ALWAYS, AFTER_UPDATE }
}
@@ -247,6 +247,20 @@ public class Config
return Boolean.parseBoolean(getString(name));
}
/**
* Returns the specified config value as an enum value. The string value of the config is
* converted to all upper case and then turned into an enum via {@link Enum#valueOf}.
*/
public <T extends Enum<T>> T getEnum (String name, Class<T> eclass, T defval) {
String value = getString(name, defval.toString());
try {
return Enum.valueOf(eclass, value.toUpperCase());
} catch (Exception e) {
log.warning("Invalid value for '" + name + "' config: '" + value + "'.");
return defval;
}
}
/**
* Massages a single string into an array and leaves existing array values as is. Simplifies
* access to parameters that are expected to be arrays.
@@ -129,7 +129,7 @@ public abstract class Getdown
{
if (SysProps.noInstall()) {
log.info("Skipping install due to 'no_install' sysprop.");
} else if (_readyToInstall) {
} else if (isUpdateAvailable()) {
log.info("Installing " + _toInstallResources.size() + " downloaded resources:");
for (Resource resource : _toInstallResources) {
resource.install(true);
@@ -260,13 +260,15 @@ public abstract class Getdown
}
}
try {
download(predownloads);
for (Resource rsrc : predownloads) {
rsrc.install(false); // install but don't validate yet
if (!predownloads.isEmpty()) {
try {
download(predownloads);
for (Resource rsrc : predownloads) {
rsrc.install(false); // install but don't validate yet
}
} catch (IOException ioe) {
log.warning("Failed to predownload resources. Continuing...", ioe);
}
} catch (IOException ioe) {
log.warning("Failed to predownload resources. Continuing...", ioe);
}
}