-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsync.ts
More file actions
30 lines (28 loc) · 1.12 KB
/
sync.ts
File metadata and controls
30 lines (28 loc) · 1.12 KB
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
import type { SqliteDatabase } from "@r_masseater/ops-harbor-core";
import { ControlPlaneClient } from "./control-plane-client";
import type { OpsHarborConfig } from "./config";
import { replaceSnapshot } from "./local-db";
export async function syncFromControlPlane(
db: SqliteDatabase,
config: OpsHarborConfig,
): Promise<{ workItems: number; events: number; synchronized?: number }> {
const client = new ControlPlaneClient(config);
let synchronized: number | undefined;
if (config.authorLogin) {
try {
const result = await client.triggerSync(config.authorLogin);
synchronized = result.synchronized;
} catch (e) {
// triggerSync is best-effort; network/control-plane errors should not abort the sync
console.error("[ops-harbor] syncFromControlPlane: triggerSync failed:", e);
synchronized = undefined;
}
}
const [workItems, events] = await Promise.all([client.listWorkItems(), client.listActivity()]);
replaceSnapshot(db, workItems, events);
return {
workItems: workItems.length,
events: events.length,
...(synchronized !== undefined ? { synchronized } : {}),
};
}