chore: refactor into new task system

This commit is contained in:
DecDuck
2025-06-06 10:00:16 +10:00
parent 951a741f3e
commit 816355be0c
3 changed files with 22 additions and 7 deletions

View File

@ -14,6 +14,9 @@ export const taskGroups = {
"import:game": {
concurrency: true,
},
"ludusavi:import": {
concurrency: false,
},
} as const;
export type TaskGroup = keyof typeof taskGroups;

View File

@ -10,6 +10,7 @@ import cleanupObjects from "./registry/objects";
import { taskGroups, type TaskGroup } from "./group";
import prisma from "../db/database";
import { type } from "arktype";
import ludusavi from "./registry/ludusavi";
// a task that has been run
type FinishedTask = {
@ -59,6 +60,7 @@ class TaskHandler {
this.saveScheduledTask(cleanupSessions);
this.saveScheduledTask(checkUpdate);
this.saveScheduledTask(cleanupObjects);
this.saveScheduledTask(ludusavi)
}
/**

View File

@ -1,7 +1,8 @@
import { defineDropTask } from "..";
import yaml from "js-yaml";
import prisma from "../internal/db/database";
import { Platform } from "~/prisma/client";
import type { LudusaviPlatformEntryCreateOrConnectWithoutLudusaviEntryInput } from "~/prisma/client/models";
import prisma from "../../db/database";
type ConnectOrCreateShorthand =
LudusaviPlatformEntryCreateOrConnectWithoutLudusaviEntryInput;
@ -19,17 +20,25 @@ type LudusaviModel = {
};
};
export default defineTask({
async run(_event) {
export default defineDropTask({
buildId: () => `ludusavi:import:${new Date().toISOString()}`,
name: "Import Ludusavi",
acls: [],
taskGroup: "ludusavi:import",
async run({ log, progress }) {
const manifest = yaml.load(
await $fetch<string>(
"https://raw.githubusercontent.com/mtkennerly/ludusavi-manifest/refs/heads/master/data/manifest.yaml",
),
) as LudusaviModel;
let currentProgress = 10;
for (const [name, data] of Object.entries(manifest)) {
progress(currentProgress);
const entries = Object.entries(manifest);
const increment = (1 / entries.length) * 0.9;
for (const [name, data] of entries) {
if (!data.files && !data.registry) continue;
console.log(name);
const iterableFiles = data.files ? Object.entries(data.files) : undefined;
@ -126,8 +135,9 @@ export default defineTask({
entries: { connectOrCreate },
},
});
}
return { result: true };
currentProgress += increment;
log(`Imported game "${name}"`);
}
},
});