web/admin: fix invalid display for LDAP Source sync status
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
e18e681c2b
commit
ee4e176039
|
@ -36,37 +36,41 @@ export class LDAPSyncStatusChart extends AKChart<LDAPSyncStats> {
|
||||||
async apiRequest(): Promise<LDAPSyncStats> {
|
async apiRequest(): Promise<LDAPSyncStats> {
|
||||||
const api = new SourcesApi(DEFAULT_CONFIG);
|
const api = new SourcesApi(DEFAULT_CONFIG);
|
||||||
const sources = await api.sourcesLdapList({});
|
const sources = await api.sourcesLdapList({});
|
||||||
let healthy = 0;
|
const metrics: { [key: string]: number } = {
|
||||||
let failed = 0;
|
healthy: 0,
|
||||||
let unsynced = 0;
|
failed: 0,
|
||||||
|
unsynced: 0,
|
||||||
|
};
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
sources.results.map(async (element) => {
|
sources.results.map(async (element) => {
|
||||||
|
// Each source should have 3 successful tasks, so the worst task overwrites
|
||||||
|
let sourceKey = "healthy";
|
||||||
try {
|
try {
|
||||||
const health = await api.sourcesLdapSyncStatusList({
|
const health = await api.sourcesLdapSyncStatusList({
|
||||||
slug: element.slug,
|
slug: element.slug,
|
||||||
});
|
});
|
||||||
|
|
||||||
health.forEach((task) => {
|
health.forEach((task) => {
|
||||||
if (task.status !== StatusEnum.Successful) {
|
if (task.status !== StatusEnum.Successful) {
|
||||||
failed += 1;
|
sourceKey = "failed";
|
||||||
}
|
}
|
||||||
const now = new Date().getTime();
|
const now = new Date().getTime();
|
||||||
const maxDelta = 3600000; // 1 hour
|
const maxDelta = 3600000; // 1 hour
|
||||||
if (!health || now - task.taskFinishTimestamp.getTime() > maxDelta) {
|
if (!health || now - task.taskFinishTimestamp.getTime() > maxDelta) {
|
||||||
unsynced += 1;
|
sourceKey = "unsynced";
|
||||||
} else {
|
|
||||||
healthy += 1;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch {
|
} catch {
|
||||||
unsynced += 1;
|
sourceKey = "unsynced";
|
||||||
}
|
}
|
||||||
|
metrics[sourceKey] += 1;
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
this.centerText = sources.pagination.count.toString();
|
this.centerText = sources.pagination.count.toString();
|
||||||
return {
|
return {
|
||||||
healthy: sources.pagination.count === 0 ? -1 : healthy,
|
healthy: sources.pagination.count === 0 ? -1 : metrics.healthy,
|
||||||
failed,
|
failed: metrics.failed,
|
||||||
unsynced,
|
unsynced: metrics.unsynced,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue