-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(jobs): add an upgrade task to delete the job records from the dat…
…abase (#30933)
- Loading branch information
1 parent
77740ac
commit 7dfc5fa
Showing
2 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
.../src/main/java/com/dotmarketing/startup/runonce/Task250107RemoveEsReadOnlyMonitorJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.dotmarketing.startup.runonce; | ||
|
||
import com.dotmarketing.common.db.DotConnect; | ||
import com.dotmarketing.exception.DotDataException; | ||
import com.dotmarketing.exception.DotRuntimeException; | ||
import com.dotmarketing.startup.StartupTask; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class Task250107RemoveEsReadOnlyMonitorJob implements StartupTask { | ||
|
||
|
||
private final String JOB_NAME = "EsReadOnlyMonitorJob"; | ||
private final String TRIGGER_NAME = "trigger29"; | ||
private final String CRON_TABLE_NAME = "qrtz_excl_cron_triggers"; | ||
private final String TRIGGER_TABLE_NAME = "qrtz_excl_triggers"; | ||
private final String JOB_TABLE_NAME = "qrtz_excl_job_details"; | ||
|
||
/** | ||
* Determines if the task should be forced to run. | ||
* | ||
* @return true if EsReadOnlyMonitorJob is found, false otherwise. | ||
*/ | ||
@Override | ||
public boolean forceRun() { | ||
String sql=String.format("SELECT * FROM %s WHERE job_name=?", JOB_TABLE_NAME); | ||
DotConnect dc=new DotConnect(); | ||
dc.setSQL(sql); | ||
|
||
dc.addParam(JOB_NAME); | ||
try { | ||
ArrayList results=dc.loadResults(); | ||
if (!results.isEmpty()){ | ||
return true; | ||
} | ||
} catch (DotDataException e) { | ||
e.printStackTrace(); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public void executeUpgrade() throws DotDataException, DotRuntimeException { | ||
removeCron(); | ||
removeTrigger(); | ||
removeJob(); | ||
} | ||
|
||
private void removeJob() throws DotDataException { | ||
DotConnect dc = new DotConnect(); | ||
dc.setSQL(String.format("DELETE FROM %s WHERE job_name = %s", JOB_TABLE_NAME, JOB_NAME)); | ||
dc.loadResult(); | ||
} | ||
|
||
private void removeTrigger() throws DotDataException { | ||
DotConnect dc = new DotConnect(); | ||
dc.setSQL(String.format("DELETE FROM %s WHERE job_name = %s", TRIGGER_TABLE_NAME, JOB_NAME)); | ||
dc.loadResult(); | ||
} | ||
|
||
private void removeCron() throws DotDataException { | ||
DotConnect dc = new DotConnect(); | ||
dc.setSQL(String.format("DELETE FROM %s WHERE trigger_name = %s", CRON_TABLE_NAME, TRIGGER_NAME)); | ||
dc.loadResult(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters