Skip to content

Commit cc06230

Browse files
committed
fix: expand multitenancy support
1 parent c866e6c commit cc06230

File tree

7 files changed

+843
-392
lines changed

7 files changed

+843
-392
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
"type-fest": "^4.41.0"
9797
},
9898
"devDependencies": {
99+
"@-xun/api-strategy": "^1.3.8",
99100
"@-xun/fs": "^2.0.0",
100101
"@-xun/mongo-test": "^3.0.4",
101102
"@-xun/symbiote": "^4.11.3",

src/tasks/ban-hammer.ts

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
import { LogTag } from '@-xun/cli/logging';
2-
import { getDb } from '@-xun/mongo-schema';
2+
import { getClient, getDb, setSchemaConfig } from '@-xun/mongo-schema';
33
import { runWithMongoSchemaMultitenancy } from '@-xun/mongo-schema/multitenant';
44

5-
import { oneSecondInMs, TargetProblem, Task } from 'universe:constant.ts';
5+
import {
6+
oneSecondInMs,
7+
TargetProblem,
8+
targetProblemBackends,
9+
Task
10+
} from 'universe:constant.ts';
11+
612
import { ErrorMessage } from 'universe:error.ts';
713
import { skipListrTask, waitForListr2OutputReady } from 'universe:util.ts';
814

915
import type { GlobalExecutionContext } from 'universe:configure.ts';
1016
import type { ActualTargetProblem } from 'universe:constant.ts';
1117
import type { TaskRunnerContext } from 'universe:util.ts';
1218

13-
const fullPrettyName = 'ban hammer';
14-
const taskType = Task.BanHammer;
19+
export const fullPrettyName = 'ban hammer';
20+
export const taskType = Task.BanHammer;
1521

1622
export default async function task(
1723
taskName: string,
@@ -26,7 +32,9 @@ export default async function task(
2632

2733
await waitForListr2OutputReady(debug);
2834

29-
await runWithMongoSchemaMultitenancy(target, async () => {
35+
await runWithMongoSchemaMultitenancy(`${target}-${taskType}`, async () => {
36+
let backend;
37+
3038
switch (target) {
3139
case TargetProblem.ElectionsCpl:
3240
case TargetProblem.ElectionsIrv:
@@ -41,8 +49,13 @@ export default async function task(
4149
return;
4250
}
4351

44-
case TargetProblem.Drive:
52+
case TargetProblem.Drive: {
53+
backend = await targetProblemBackends.drive;
54+
break;
55+
}
56+
4557
case TargetProblem.Qoverflow: {
58+
backend = await targetProblemBackends.qoverflow;
4659
break;
4760
}
4861

@@ -51,8 +64,16 @@ export default async function task(
5164
}
5265
}
5366

54-
const bannedCount = await unleashBanHammer();
67+
// ? Prewarm shared memory
68+
await getClient({
69+
MONGODB_URI: getConfig(`${target}.mongodbUri`, 'string')
70+
});
5571

72+
setSchemaConfig(backend.db.getSchemaConfig());
73+
74+
const [bannedCount, cursor] = await unleashBanHammer();
75+
76+
await cursor.close();
5677
taskLog([LogTag.IF_NOT_QUIETED], '~%O clients are currently banned', bannedCount);
5778
});
5879

@@ -273,11 +294,9 @@ export default async function task(
273294
debug('aggregation pipeline: %O', pipeline);
274295

275296
const cursor = db.collection('request-log').aggregate(pipeline);
297+
await cursor.toArray();
276298

277-
await cursor.next();
278-
await cursor.close();
279-
280-
return db.collection('limited-log').estimatedDocumentCount();
299+
return [db.collection('limited-log').estimatedDocumentCount(), cursor] as const;
281300
}
282301

283302
function getConfigFor(target: ActualTargetProblem) {

src/tasks/prune-data.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import type { GlobalExecutionContext } from 'universe:configure.ts';
1717
import type { ActualTargetProblem } from 'universe:constant.ts';
1818
import type { TaskRunnerContext } from 'universe:util.ts';
1919

20-
const fullPrettyName = 'prune data';
21-
const taskType = Task.PruneData;
20+
export const fullPrettyName = 'prune data';
21+
export const taskType = Task.PruneData;
2222

2323
const maxAllowedBytes = parseBytes('450mb')!;
2424

@@ -68,7 +68,7 @@ export default async function task(
6868

6969
await waitForListr2OutputReady(debug);
7070

71-
await runWithMongoSchemaMultitenancy(target, async () => {
71+
await runWithMongoSchemaMultitenancy(`${target}-${taskType}`, async () => {
7272
switch (target) {
7373
case TargetProblem.ElectionsCpl:
7474
case TargetProblem.ElectionsIrv:

0 commit comments

Comments
 (0)