in plugin-azure-agent/src/main/kotlin/jetbrains/buildServer/clouds/azure/AzureCustomDataReader.kt [17:57]
fun process(shouldRetryOnFail: Boolean) : Boolean {
val customDataFile = File(customDataFileName)
val maxDelay = TeamCityProperties.getLong("teamcity.azure.customData.retry.maxDelay", 30_000)
val maxRetries = if (shouldRetryOnFail) TeamCityProperties.getInteger("teamcity.azure.customData.retry.maxRetries", 7) else 0
val delay = TeamCityProperties.getLong("teamcity.azure.customData.retry.delay", 5_000)
val customData = try {
Retry<String>()
.maxDelay(maxDelay)
.maxRetries(maxRetries)
.intervalFunction { attemptNo ->
delay * BACKOFF_FACTOR.pow(attemptNo - 1).toLong()
}
.logRetry { attemptNo, throwable ->
LOG.warnAndDebugDetails("Failed to read Azure custom data file $customDataFile attempt $attemptNo", throwable)
}
.retryOn(IOException::class.java, EmptyCustomDataFileException::class.java)
.block {
myFileUtils
.readFile(customDataFile)
.also {
if (it.isBlank()) {
throw EmptyCustomDataFileException("Azure custom data file $customDataFile is empty")
}
}
}
} catch (e: FileNotFoundException) {
val message = AzureUtils.getFileNotFoundMessage(e)
LOG.info(String.format(FAILED_TO_READ_CUSTOM_DATA_FILE, customDataFile, message))
LOG.debug(e)
return false
} catch (e: EmptyCustomDataFileException) {
LOG.info(e.message)
return false
} catch (e: Exception) {
LOG.info(String.format(FAILED_TO_READ_CUSTOM_DATA_FILE, customDataFile, e.message))
LOG.debug(e)
return false
}
return parseCustomData(customData)
}