Disable retries if maxAllowedRetries is 0 Allow admins to disable retries globally. Change-Id: I5394c450104f1adf86a0287a0fa7ac1ae0af97a5
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/Configuration.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/Configuration.java index 3c3f67b..fbe38bc 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/Configuration.java +++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/Configuration.java
@@ -37,6 +37,7 @@ public static final String MAX_ALLOWED_TRIES = "maxAllowedTries"; public static final String MAX_ALLOWED_RETRY_INTERVAL = "maxAllowedRetryInterval"; + public static final int UNSET_CONFIG_INT = -1; public static final int DEFAULT_TIMEOUT_MS = 5000; public static final int DEFAULT_MAX_TRIES = 5; public static final int DEFAULT_RETRY_INTERVAL = 1000; @@ -69,7 +70,7 @@ allowedUrlPatterns = cfg.getStringList(ALLOWED_URL_PATTERN); maxAllowedConnectionTimeout = cfg.getInt(MAX_ALLOWED_CONNECTION_TIMEOUT, 0); maxAllowedSocketTimeout = cfg.getInt(MAX_ALLOWED_SOCKET_TIMEOUT, 0); - maxAllowedTries = cfg.getInt(MAX_ALLOWED_TRIES, 0); + maxAllowedTries = cfg.getInt(MAX_ALLOWED_TRIES, UNSET_CONFIG_INT); maxAllowedRetryInterval = cfg.getInt(MAX_ALLOWED_RETRY_INTERVAL, 0); }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/RemoteConfig.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/RemoteConfig.java index 5b9686a..2949b90 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/RemoteConfig.java +++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/RemoteConfig.java
@@ -14,6 +14,8 @@ package com.googlesource.gerrit.plugins.webhooks; +import static com.googlesource.gerrit.plugins.webhooks.Configuration.UNSET_CONFIG_INT; + import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; import java.util.Arrays; @@ -83,9 +85,10 @@ } public int getMaxTries() { + int maxAllowedRetries = global.getMaxAllowedTries(); int maxTries = config.getInt(REMOTE, name, MAX_TRIES, global.getMaxTries()); - return (global.getMaxAllowedTries() > 0) - ? Math.min(maxTries, global.getMaxAllowedTries()) + return (maxAllowedRetries != UNSET_CONFIG_INT) + ? Math.min(maxTries, maxAllowedRetries) : maxTries; }
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md index f4b3250..af1fbed 100644 --- a/src/main/resources/Documentation/config.md +++ b/src/main/resources/Documentation/config.md
@@ -89,6 +89,7 @@ @PLUGIN@.maxAllowedTries : Maximum allowed value for the retries. If a value greater than this is configured in the @PLUGIN@.config, this value will be chosen instead. + If this is set to 0, retries are disabled. @PLUGIN@.maxAllowedRetryInterval : Maximum allowed value for the retry interval. If a value greater than