Skip to content

Commit

Permalink
fix backported tasks executor
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgonzalez committed Dec 7, 2024
1 parent d5d6a22 commit 43fa2ec
Showing 1 changed file with 39 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ private StartupTasksExecutor() {
this.firstTimeStart = (Config.DB_VERSION==0);
}

public static synchronized StartupTasksExecutor getInstance() {
if (executor == null)
executor = new StartupTasksExecutor();
return executor;
}
public static synchronized StartupTasksExecutor getInstance() {
if (executor == null)
executor = new StartupTasksExecutor();
return executor;
}


private final String createTableSQL() {
private final String createTableSQL() {

return (DbConnectionFactory.isPostgres())
? pgCreate
: DbConnectionFactory.isMySql()
? myCreate
: DbConnectionFactory.isOracle()
? oraCreate
: msCreate;
}
return (DbConnectionFactory.isPostgres())
? pgCreate
: DbConnectionFactory.isMySql()
? myCreate
: DbConnectionFactory.isOracle()
? oraCreate
: msCreate;
}

/**
* Returns the SQL to create the data_version table
Expand All @@ -73,17 +73,17 @@ private final String createDataVersionTableSQL() {
return (DbConnectionFactory.isPostgres())
? pgCreateDataVersion
: DbConnectionFactory.isMySql()
? myCreateDataVersion
: DbConnectionFactory.isOracle()
? oraCreateDataVersion
: msCreateDataVersion;
? myCreateDataVersion
: DbConnectionFactory.isOracle()
? oraCreateDataVersion
: msCreateDataVersion;
}

/**
* This will create the db version table if it does not already exist
* @return
*/
private boolean insureDbVersionTable() {
private boolean insureDbVersionTable() {

try {
currentDbVersion();
Expand Down Expand Up @@ -210,7 +210,7 @@ public void executeStartUpTasks() throws DotDataException {
HibernateUtil.closeAndCommitTransaction();
}


}

/**
Expand Down Expand Up @@ -238,7 +238,7 @@ public void executeSchemaUpgrades() throws DotDataException {
Logger.info(this, "Database version: " + Config.DB_VERSION);

String name = null;

for (Class<?> c : TaskLocatorUtil.getStartupRunOnceTaskClasses()) {
name = c.getCanonicalName();
name = name.substring(name.lastIndexOf(".") + 1);
Expand All @@ -261,12 +261,12 @@ public void executeSchemaUpgrades() throws DotDataException {
task.executeUpgrade();

}

new DotConnect()
.setSQL(INSERT)
.addParam(taskId)
.addParam(new Date())
.loadResult();
.setSQL(INSERT)
.addParam(taskId)
.addParam(new Date())
.loadResult();
Logger.info(this, "Database upgraded to version: " + taskId);
if(!TaskLocatorUtil.getTaskClassesNoTransaction().contains(c)){
HibernateUtil.closeAndCommitTransaction();
Expand All @@ -276,7 +276,9 @@ public void executeSchemaUpgrades() throws DotDataException {
} catch (Exception e) {
taskFailure(e);
} finally {
HibernateUtil.closeAndCommitTransaction();
if(!TaskLocatorUtil.getTaskClassesNoTransaction().contains(c)){
HibernateUtil.closeAndCommitTransaction();
}
}

}
Expand Down Expand Up @@ -344,15 +346,17 @@ public void executeDataUpgrades() throws DotDataException {
} catch (Exception e) {
taskFailure(e);
} finally {
HibernateUtil.closeAndCommitTransaction();
if(!TaskLocatorUtil.getTaskClassesNoTransaction().contains(c)){
HibernateUtil.closeAndCommitTransaction();
}
}

}

Logger.info(this, "Finishing data upgrade tasks.");
}

/**
/**
* This will execute all the UT that were backported to the LTS version.
* Will be run everytime the server gets restarted just like the Startup Tasks.
* But these will be run after the upgradeTasks.
Expand All @@ -367,12 +371,14 @@ public void executeBackportedTasks() throws DotDataException {


for (Class<?> c : TaskLocatorUtil.getBackportedUpgradeTaskClasses()) {
HibernateUtil.startTransaction();
if(!TaskLocatorUtil.getTaskClassesNoTransaction().contains(c)){
HibernateUtil.startTransaction();
}
name = c.getCanonicalName();
name = name.substring(name.lastIndexOf(".") + 1);
String id = getTaskId(name);
String id = getTaskId(name);
int taskId = Integer.parseInt(id);
if (StartupTask.class.isAssignableFrom(c) && taskId > Config.DB_VERSION) {
if (StartupTask.class.isAssignableFrom(c) && taskId > Config.DB_VERSION) {
StartupTask task = (StartupTask) c.getDeclaredConstructor().newInstance();
if (task.forceRun()) {
if(!TaskLocatorUtil.getTaskClassesNoTransaction().contains(c)){
Expand Down Expand Up @@ -420,4 +426,4 @@ private void taskFailure(Throwable e) throws DotHibernateException {
}


}
}

0 comments on commit 43fa2ec

Please sign in to comment.