From 1ac7e0279eff906b5f08171740722199f1145a54 Mon Sep 17 00:00:00 2001 From: erickgonzalez Date: Fri, 19 Jul 2024 15:49:32 -0600 Subject: [PATCH] #29240 include in 23.10.24 LTS --- dotCMS/hotfix_tracking.md | 3 +- .../startup/StartupTasksExecutor.java | 46 ++++++++++--------- .../resources/dotmarketing-config.properties | 2 +- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/dotCMS/hotfix_tracking.md b/dotCMS/hotfix_tracking.md index 7a4bfd7260e9..4718e6d5a9f6 100644 --- a/dotCMS/hotfix_tracking.md +++ b/dotCMS/hotfix_tracking.md @@ -125,4 +125,5 @@ This maintenance release includes the following code fixes: 118. https://github.com/dotCMS/core/issues/26421 : Block Editor: Add align-justify option to menu #26421 119. https://github.com/dotCMS/core/issues/27537 : Download database not working in latest version #27537 120. https://github.com/dotCMS/core/issues/27871 : refactor pg_dump inclusion in our docker image #27871 -121. SI-72 \ No newline at end of file +121. SI-72 +122. https://github.com/dotCMS/core/issues/29240 : UT keep running even though one failed #29240 \ No newline at end of file diff --git a/dotCMS/src/main/java/com/dotmarketing/startup/StartupTasksExecutor.java b/dotCMS/src/main/java/com/dotmarketing/startup/StartupTasksExecutor.java index d0665757af93..0e3874bcf2eb 100644 --- a/dotCMS/src/main/java/com/dotmarketing/startup/StartupTasksExecutor.java +++ b/dotCMS/src/main/java/com/dotmarketing/startup/StartupTasksExecutor.java @@ -1,5 +1,6 @@ package com.dotmarketing.startup; +import com.dotmarketing.exception.DotHibernateException; import com.google.common.annotations.VisibleForTesting; import java.sql.Connection; import java.util.Date; @@ -199,12 +200,7 @@ public void executeStartUpTasks() throws DotDataException { } Logger.info(this, "Finishing startup tasks."); } catch (Throwable e) { - HibernateUtil.rollbackTransaction(); - Logger.error(this, "FATAL: Unable to execute the upgrade task : " + name, e); - if(Config.getBooleanProperty("SYSTEM_EXIT_ON_STARTUP_FAILURE", true)){ - e.printStackTrace(); - System.exit(1); - } + taskFailure(e); } finally { // This will commit the changes and close the connection HibernateUtil.closeAndCommitTransaction(); @@ -270,11 +266,7 @@ public void executeSchemaUpgrades() throws DotDataException { Config.DB_VERSION = taskId; } } catch (Exception e) { - HibernateUtil.rollbackTransaction(); - if (Config.getBooleanProperty("SYSTEM_EXIT_ON_STARTUP_FAILURE", true)) { - Logger.error(this, "FATAL: " +e.getMessage(),e); - System.exit(1); - } + taskFailure(e); } finally { HibernateUtil.closeAndCommitTransaction(); } @@ -338,11 +330,7 @@ public void executeDataUpgrades() throws DotDataException { Config.DATA_VERSION = taskId; } } catch (Exception e) { - HibernateUtil.rollbackTransaction(); - if (Config.getBooleanProperty("SYSTEM_EXIT_ON_STARTUP_FAILURE", true)) { - Logger.error(this, "FATAL: " + e.getMessage(), e); - System.exit(1); - } + taskFailure(e); } finally { HibernateUtil.closeAndCommitTransaction(); } @@ -386,12 +374,7 @@ public void executeBackportedTasks() throws DotDataException { } Logger.info(this, "Finishing Backported tasks."); } catch (Throwable e) { - HibernateUtil.rollbackTransaction(); - Logger.error(this, "FATAL: Unable to execute the upgrade task : " + name, e); - if(Config.getBooleanProperty("SYSTEM_EXIT_ON_STARTUP_FAILURE", true)){ - e.printStackTrace(); - System.exit(1); - } + taskFailure(e); } finally { // This will commit the changes and close the connection HibernateUtil.closeAndCommitTransaction(); @@ -400,6 +383,25 @@ public void executeBackportedTasks() throws DotDataException { } + private void taskFailure(Throwable e) throws DotHibernateException { + HibernateUtil.rollbackTransaction(); + for(int i = 0; i < 3; i++){ + System.err.println("FATAL ERROR RUNNING TASK: " + e.getMessage()); + Logger.error(this, "FATAL ERROR RUNNING TASK: " + e.getMessage(), e); + } + + e.printStackTrace(); + + if (Config.getBooleanProperty("SYSTEM_EXIT_ON_STARTUP_FAILURE", true)) { + try { + Thread.sleep(10000); + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + Logger.debug(this,"Thread was interrupted", ex); + } + System.exit(1); + } + } } diff --git a/dotCMS/src/main/resources/dotmarketing-config.properties b/dotCMS/src/main/resources/dotmarketing-config.properties index 4a140239942c..406bb44113ce 100644 --- a/dotCMS/src/main/resources/dotmarketing-config.properties +++ b/dotCMS/src/main/resources/dotmarketing-config.properties @@ -1,4 +1,4 @@ -SYSTEM_EXIT_ON_STARTUP_FAILURE=false +SYSTEM_EXIT_ON_STARTUP_FAILURE=true CONTENT_PALETTE_HIDDEN_CONTENT_TYPES=Host,Vanityurl,Languagevariable,persona,forms EMAIL_SYSTEM_ADDRESS = website@dotcms.com