cleanup only in SCP and dev
MODIFY
src/locking/LockingManager.ts
src/locking/LockingManager.ts
import Lock, { LockEntity, LockType } from '../types/Locking';
import BackendError from '../exception/BackendError';
-import Configuration from '../utils/Configuration';
import Cypher from '../utils/Cypher';
import LockingStorage from '../storage/mongodb/LockingStorage';
import Logging from '../utils/Logging';
import { ServerAction } from '../types/Server';
import Utils from '../utils/Utils';
-import cfenv from 'cfenv';
-import os from 'os';
const MODULE_NAME = 'LockingManager';
@@ -82,10 +79,12 @@ export default class LockingManager {
return true;
}
- public static async cleanUpLocks(): Promise<void> {
+ public static async cleanupLocks(doCleanup = true): Promise<void> {
+ if (doCleanup) {
const hostname = Utils.getHostname();
await LockingStorage.deleteLockByHostname(hostname);
}
+ }
private static createLock(tenantID: string, entity: LockEntity, key: string, type: LockType = LockType.EXCLUSIVE): Lock {
if (!tenantID) {
@@ -120,7 +119,7 @@ export default class LockingManager {
key: key.toLowerCase(),
type: type,
timestamp: new Date(),
- hostname: Configuration.isCloudFoundry() ? cfenv.getAppEnv().name : os.hostname()
+ hostname: Utils.getHostname()
};
}
}

MODIFY
src/start.ts
src/start.ts
@@ -128,7 +128,7 @@ export default class Bootstrap {
// Locks remain in storage if server crashes
// Delete acquired database locks with same hostname
- await LockingManager.cleanUpLocks();
+ await LockingManager.cleanupLocks(Configuration.isCloudFoundry() || Utils.isDevelopmentEnv());
}
} catch (error) {
// Log

MODIFY
src/storage/mongodb/LoggingStorage.ts
src/storage/mongodb/LoggingStorage.ts
@@ -67,7 +67,7 @@ export default class LoggingStorage {
actionOnUserID: Utils.convertUserToObjectID(logToSave.actionOnUser),
level: logToSave.level,
source: logToSave.source,
- host: logToSave.host ? logToSave.host : (Configuration.isCloudFoundry() ? cfenv.getAppEnv().name : os.hostname()),
+ host: logToSave.host ? logToSave.host : (Utils.getHostname()),
process: logToSave.process ? logToSave.process : (cluster.isWorker ? 'worker ' + cluster.worker.id.toString() : 'master'),
type: logToSave.type,
timestamp: Utils.convertToDate(logToSave.timestamp),

cleanup only in SCP and dev