Add a shutdownhook to remove jobs owned by the process (#8896)

Co-authored-by: Suresh Kumar Anaparti <sureshkumar.anaparti@gmail.com>
This commit is contained in:
dahn 2024-04-19 09:18:41 +02:00 committed by GitHub
parent 8a101fbbc1
commit 5f8450f28f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -316,6 +316,7 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager, Runna
_sanity = _sanityExecutor.scheduleAtFixedRate(new SanityCheck(), 1, _sanityCheckInterval, TimeUnit.DAYS); _sanity = _sanityExecutor.scheduleAtFixedRate(new SanityCheck(), 1, _sanityCheckInterval, TimeUnit.DAYS);
} }
Runtime.getRuntime().addShutdownHook(new AbandonJob());
TransactionLegacy usageTxn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); TransactionLegacy usageTxn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
try { try {
if (_heartbeatLock.lock(3)) { // 3 second timeout if (_heartbeatLock.lock(3)) { // 3 second timeout
@ -345,9 +346,11 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager, Runna
if (_sanity != null) { if (_sanity != null) {
_sanity.cancel(true); _sanity.cancel(true);
} }
return true; return true;
} }
@Override @Override
public void run() { public void run() {
(new ManagedContextRunnable() { (new ManagedContextRunnable() {
@ -2183,4 +2186,17 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager, Runna
} }
} }
} }
private class AbandonJob extends Thread {
@Override
public void run() {
s_logger.info("exitting Usage Manager");
deleteOpenjob();
}
private void deleteOpenjob() {
UsageJobVO job = _usageJobDao.isOwner(_hostname, _pid);
if (job != null) {
_usageJobDao.remove(job.getId());
}
}
}
} }