Skip to content

Commit

Permalink
fix: Refactored version check method
Browse files Browse the repository at this point in the history
Refs: #DEV-11775
  • Loading branch information
nirikash committed Jun 14, 2024
1 parent bd50018 commit 21cf562
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,16 @@ private void logWeasyPrintVersionFromHeader(Response response) {
String actualWeasyPrintVersion = response.getHeaderString(WEASYPRINT_VERSION_HEADER);
String actualPythonVersion = response.getHeaderString(PYTHON_VERSION_HEADER);

logWeasyPrintVersion(actualWeasyPrintVersion, weasyPrintVersion, "WeasyPrint");
logWeasyPrintVersion(actualPythonVersion, pythonVersion, "Python");
}
boolean hasWeasyPrintVersionChanged = hasVersionChanged(actualWeasyPrintVersion, weasyPrintVersion);
boolean hasPythonVersionChanged = hasVersionChanged(actualPythonVersion, pythonVersion);

public void logWeasyPrintVersion(String actualVersion, AtomicReference<String> version, String nameInMessage) {
if (!isEmpty(actualVersion)
&& !actualVersion.equals(version.getAndSet(actualVersion))) {
logger.info(String.format("Using WeasyPrint Service with %s version: %s", nameInMessage, actualVersion));
if (hasWeasyPrintVersionChanged || hasPythonVersionChanged) {
logger.info(String.format("WeasyPrintService uses WeasyPrint version '%s' and Python version '%s'", actualWeasyPrintVersion, actualPythonVersion));
}
}

public boolean hasVersionChanged(String actualVersion, AtomicReference<String> version) {
return (!isEmpty(actualVersion)
&& !actualVersion.equals(version.getAndSet(actualVersion)));
}
}

0 comments on commit 21cf562

Please sign in to comment.