Skip to content

Commit b7b88cf

Browse files
authored
Check integrity task (#364)
1 parent d060533 commit b7b88cf

8 files changed

Lines changed: 136 additions & 32 deletions

File tree

i18n/locales/en_us.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@
755755
"cleanupSessionsDescription": "Cleans up expired sessions to save space and ensure security.",
756756
"cleanupSessionsName": "Clean up sessions."
757757
},
758+
"utilityTitle": "Utility tasks",
758759
"viewTask": "View {arrow}",
759760
"weeklyScheduledTitle": "Weekly scheduled tasks"
760761
}

pages/admin/task/index.vue

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,44 @@
166166
</div>
167167
</li>
168168
</ul>
169+
<h2 class="text-sm font-medium text-zinc-400 mt-8">
170+
{{ $t("tasks.admin.utilityTitle") }}
171+
</h2>
172+
<ul role="list" class="mt-4 grid grid-cols-1 lg:grid-cols-2 gap-6">
173+
<li
174+
v-for="task in other"
175+
:key="task"
176+
class="col-span-1 divide-y divide-gray-200 rounded-lg bg-zinc-800 border border-zinc-700 shadow-sm"
177+
>
178+
<div class="flex w-full items-center justify-between space-x-6 p-6">
179+
<div class="flex-1">
180+
<div class="flex items-center space-x-2">
181+
<h3 class="text-sm font-medium text-zinc-100">
182+
{{ scheduledTasks[task].name }}
183+
</h3>
184+
</div>
185+
<p class="mt-1 text-sm text-zinc-400">
186+
{{ scheduledTasks[task].description }}
187+
</p>
188+
<button
189+
class="mt-3 rounded-md text-xs font-medium text-zinc-100 hover:text-zinc-300 focus:outline-none focus:ring-2 focus:ring-zinc-100 focus:ring-offset-2"
190+
@click="() => startTask(task)"
191+
>
192+
<i18n-t
193+
keypath="tasks.admin.execute"
194+
tag="span"
195+
scope="global"
196+
class="inline-flex items-center gap-x-1"
197+
>
198+
<template #arrow>
199+
<PlayIcon class="size-4" aria-hidden="true" />
200+
</template>
201+
</i18n-t>
202+
</button>
203+
</div>
204+
</div>
205+
</li>
206+
</ul>
169207
</div>
170208
</div>
171209
</div>
@@ -185,7 +223,7 @@ definePageMeta({
185223
186224
const { t } = useI18n();
187225
188-
const { runningTasks, historicalTasks, dailyTasks, weeklyTasks } =
226+
const { runningTasks, historicalTasks, dailyTasks, weeklyTasks, other } =
189227
await $dropFetch("/api/v1/admin/task");
190228
191229
const liveRunningTasks = ref(
@@ -219,9 +257,9 @@ const scheduledTasks: {
219257
name: "",
220258
description: "",
221259
},
222-
debug: {
223-
name: "",
224-
description: "",
260+
"import:check-integrity": {
261+
name: "Check Integrity",
262+
description: "Re-imports all versions and updates their manifests.",
225263
},
226264
};
227265

server/api/v1/admin/task/index.get.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import aclManager from "~/server/internal/acls";
22
import prisma from "~/server/internal/db/database";
33
import taskHandler from "~/server/internal/tasks";
4+
import type { TaskGroup } from "~/server/internal/tasks/group";
45

56
export default defineEventHandler(async (h3) => {
67
const allowed = await aclManager.allowSystemACL(h3, ["task:read"]);
@@ -38,6 +39,7 @@ export default defineEventHandler(async (h3) => {
3839
});
3940
const dailyTasks = await taskHandler.dailyTasks();
4041
const weeklyTasks = await taskHandler.weeklyTasks();
42+
const other: TaskGroup[] = ["import:check-integrity"];
4143

42-
return { runningTasks, historicalTasks, dailyTasks, weeklyTasks };
44+
return { runningTasks, historicalTasks, dailyTasks, weeklyTasks, other };
4345
});

server/internal/services/torrential/droplet-interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class DropletInterfaceManager {
217217
run: async (message) => {
218218
const callbacks = this.callbacks.get(message.messageId);
219219
if (!callbacks) {
220-
logger.warn(
220+
logger.debug(
221221
`got a droplet message with old message id: ${message.type}, ${message.messageId}`,
222222
);
223223
return undefined;

server/internal/tasks/group.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export const taskGroups = {
1717
"import:version": {
1818
concurrency: true,
1919
},
20-
debug: {
21-
concurrency: true,
20+
"import:check-integrity": {
21+
concurrency: false,
2222
},
2323
} as const;
2424

server/internal/tasks/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import type { MinimumRequestObject } from "~/server/h3";
22
import type { GlobalACL } from "../acls";
33
import aclManager from "../acls";
4-
5-
import cleanupInvites from "./registry/invitations";
6-
import cleanupSessions from "./registry/sessions";
7-
import checkUpdate from "./registry/update";
8-
import cleanupObjects from "./registry/objects";
94
import { taskGroups, type TaskGroup } from "./group";
105
import prisma from "../db/database";
116
import { ArkErrors, type } from "arktype";
127
import pino from "pino";
138
import { logger } from "~/server/internal/logging";
149
import { Writable } from "node:stream";
1510

11+
import cleanupInvites from "./registry/invitations";
12+
import cleanupSessions from "./registry/sessions";
13+
import checkUpdate from "./registry/update";
14+
import cleanupObjects from "./registry/objects";
15+
import checkIntegrity from "./registry/check-integrity";
16+
1617
type TaskActionLink = `${string}:${string}`;
1718

1819
// a task that has been run
@@ -65,7 +66,7 @@ class TaskHandler {
6566
this.saveScheduledTask(cleanupSessions);
6667
this.saveScheduledTask(checkUpdate);
6768
this.saveScheduledTask(cleanupObjects);
68-
//this.saveScheduledTask(debug);
69+
this.saveScheduledTask(checkIntegrity);
6970
}
7071

7172
/**
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import prisma from "~/server/internal/db/database";
2+
import { defineDropTask, wrapTaskContext } from "..";
3+
import { libraryManager } from "../../library";
4+
5+
export default defineDropTask({
6+
buildId: () => `import:check-integrity:${new Date().toISOString()}`,
7+
name: "Check version integrity",
8+
acls: ["system:import:version:read"],
9+
taskGroup: "import:check-integrity",
10+
async run({ progress, logger, addAction }) {
11+
const versions = await prisma.gameVersion.findMany({
12+
where: {
13+
versionPath: {
14+
not: null,
15+
},
16+
},
17+
select: {
18+
versionId: true,
19+
versionPath: true,
20+
displayName: true,
21+
game: {
22+
select: {
23+
libraryId: true,
24+
libraryPath: true,
25+
mName: true,
26+
},
27+
},
28+
},
29+
});
30+
31+
logger.info(`Checking version integrity for ${versions.length} versions`);
32+
33+
let i = 0;
34+
const progressStep = 100 / versions.length;
35+
for (const version of versions) {
36+
const displayName = `${version.game.mName} ${version.displayName ?? version.versionPath}`;
37+
logger.info(`Starting integrity check for ${displayName}`);
38+
39+
const library = await libraryManager.getLibrary(version.game.libraryId);
40+
if (!library) {
41+
logger.warn(`No library for ${displayName}`);
42+
continue;
43+
}
44+
45+
const min = i * progressStep;
46+
const max = (i + 1) * progressStep;
47+
const taskContext = wrapTaskContext(
48+
{ progress, logger, addAction },
49+
{ min, max, prefix: `re-check ${displayName}` },
50+
);
51+
52+
const manifest = await library.generateDropletManifest(
53+
version.game.libraryPath,
54+
version.versionPath!,
55+
taskContext.progress,
56+
(value) => {
57+
taskContext.logger.info(value);
58+
},
59+
);
60+
61+
// SAFETY: this is requested from the database
62+
// eslint-disable-next-line drop/no-prisma-delete
63+
await prisma.gameVersion.update({
64+
where: {
65+
versionId: version.versionId,
66+
},
67+
data: {
68+
versionId: crypto.randomUUID(),
69+
dropletManifest: manifest,
70+
},
71+
});
72+
73+
logger.info(`Finished integrity check for ${displayName}`);
74+
i++;
75+
}
76+
77+
logger.info("Done");
78+
progress(100);
79+
},
80+
});

server/internal/tasks/registry/debug.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)