mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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:
parent
8a101fbbc1
commit
5f8450f28f
@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user