MCPcopy
hub / github.com/msgbyte/tianji / upsert

Method upsert

src/server/model/monitor/manager.ts:32–78  ·  view source on GitHub ↗

* create or update

(data: MonitorUpsertData)

Source from the content-addressed store, hash-verified

30 * create or update
31 */
32 async upsert(data: MonitorUpsertData): Promise<MonitorWithNotification> {
33 let monitor: MonitorWithNotification;
34 const { id, workspaceId, notificationIds = [], ...others } = data;
35 if (id) {
36 // update
37 monitor = await prisma.monitor.update({
38 where: {
39 id,
40 workspaceId,
41 },
42 data: {
43 ...others,
44 notifications: {
45 set: notificationIds.map((id) => ({ id })),
46 },
47 },
48 include: {
49 notifications: true,
50 },
51 });
52 } else {
53 // create
54 monitor = await prisma.monitor.create({
55 data: {
56 ...others,
57 workspaceId,
58 notifications: {
59 connect: notificationIds.map((id) => ({ id })),
60 },
61 },
62 include: {
63 notifications: true,
64 },
65 });
66 }
67
68 if (this.monitorRunner[monitor.id]) {
69 // Stop and remove old
70 this.monitorRunner[monitor.id].stopMonitor();
71 delete this.monitorRunner[monitor.id];
72 }
73
74 const runner = await this.createRunner(monitor);
75 runner.startMonitor();
76
77 return monitor;
78 }
79
80 async delete(workspaceId: string, monitorId: string) {
81 const runner = this.getRunner(monitorId);

Callers 11

findSessionFunction · 0.45
feedStateUpsertFunction · 0.45
upsertStoreInfoFunction · 0.45
findSessionFunction · 0.45
saveMonitorStatusFunction · 0.45
billing.tsFile · 0.45
aiGateway.tsFile · 0.45
worker.tsFile · 0.45
monitor.tsFile · 0.45
warehouse.spec.tsFile · 0.45

Calls 3

createRunnerMethod · 0.95
stopMonitorMethod · 0.80
startMonitorMethod · 0.80

Tested by

no test coverage detected