mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-14 00:31:25 +10:00
chore: refactor into new task system
This commit is contained in:
@ -14,6 +14,9 @@ export const taskGroups = {
|
||||
"import:game": {
|
||||
concurrency: true,
|
||||
},
|
||||
"ludusavi:import": {
|
||||
concurrency: false,
|
||||
},
|
||||
} as const;
|
||||
|
||||
export type TaskGroup = keyof typeof taskGroups;
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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}"`);
|
||||
}
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user