-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinstrumentation.ts
More file actions
44 lines (37 loc) · 1.46 KB
/
instrumentation.ts
File metadata and controls
44 lines (37 loc) · 1.46 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
(BigInt.prototype as any).toJSON = function () {
return this.toString();
};
const { closeActiveSessions } = await import('./utils/closesessions');
await closeActiveSessions();
if (process.env.NEXT_MULTI?.toLowerCase() === 'true') {
const prisma = (await import('./utils/database')).default;
console.log("[STARTUP] Starting batch assignment for multi-container mode");
const workspaces = await prisma.workspace.findMany({
select: { groupId: true }
});
if (workspaces.length === 0) {
console.log("[STARTUP] No workspaces found to assign batches");
} else {
const shuffled = [...workspaces].sort(() => Math.random() - 0.5);
const batchUpdates = shuffled.map((workspace, index) => {
const batchId = (index % 8) + 1;
return prisma.workspace.update({
where: { groupId: workspace.groupId },
data: { batchId }
});
});
await prisma.$transaction(batchUpdates);
const distribution = await prisma.workspace.groupBy({
by: ['batchId'],
_count: { groupId: true }
});
console.log("[STARTUP] Batch assignment completed:");
distribution.forEach(({ batchId, _count }) => {
console.log(` Batch ${batchId}: ${_count.groupId} workspaces`);
});
}
}
}
}