-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.ts
32 lines (28 loc) · 1.04 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { PluginLoader } from '@awarns/core';
import { syncedRecordsStore } from './internal/stores';
import { RecordsStore } from './stores';
import { getLogger } from '@awarns/core/utils/logger';
export * from './stores';
export * from './exporters';
export * from './tasks';
export interface PersistenceConfig {
externalRecordsStore?: RecordsStore;
oldRecordsMaxAgeHours?: number;
}
export function registerPersistencePlugin(config: PersistenceConfig = {}): PluginLoader {
return () => {
if (config.externalRecordsStore) {
syncedRecordsStore.setExternalStore(config.externalRecordsStore);
}
if (config.oldRecordsMaxAgeHours !== undefined) {
syncedRecordsStore.setClearOldThreshold(config.oldRecordsMaxAgeHours);
}
const detachedDBMaintenance = async () => {
await syncedRecordsStore.sync();
await syncedRecordsStore.clearOld();
};
detachedDBMaintenance().catch((err) => {
getLogger('PersistencePlugin').error(`Could not complete DB maintenance. Reason: ${err.stack ?? err}`);
});
};
}