mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-15 01:01:20 +10:00
chore: refactor into new task system
This commit is contained in:
@ -14,6 +14,9 @@ export const taskGroups = {
|
|||||||
"import:game": {
|
"import:game": {
|
||||||
concurrency: true,
|
concurrency: true,
|
||||||
},
|
},
|
||||||
|
"ludusavi:import": {
|
||||||
|
concurrency: false,
|
||||||
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export type TaskGroup = keyof typeof taskGroups;
|
export type TaskGroup = keyof typeof taskGroups;
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import cleanupObjects from "./registry/objects";
|
|||||||
import { taskGroups, type TaskGroup } from "./group";
|
import { taskGroups, type TaskGroup } from "./group";
|
||||||
import prisma from "../db/database";
|
import prisma from "../db/database";
|
||||||
import { type } from "arktype";
|
import { type } from "arktype";
|
||||||
|
import ludusavi from "./registry/ludusavi";
|
||||||
|
|
||||||
// a task that has been run
|
// a task that has been run
|
||||||
type FinishedTask = {
|
type FinishedTask = {
|
||||||
@ -59,6 +60,7 @@ class TaskHandler {
|
|||||||
this.saveScheduledTask(cleanupSessions);
|
this.saveScheduledTask(cleanupSessions);
|
||||||
this.saveScheduledTask(checkUpdate);
|
this.saveScheduledTask(checkUpdate);
|
||||||
this.saveScheduledTask(cleanupObjects);
|
this.saveScheduledTask(cleanupObjects);
|
||||||
|
this.saveScheduledTask(ludusavi)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
|
import { defineDropTask } from "..";
|
||||||
import yaml from "js-yaml";
|
import yaml from "js-yaml";
|
||||||
import prisma from "../internal/db/database";
|
|
||||||
import { Platform } from "~/prisma/client";
|
import { Platform } from "~/prisma/client";
|
||||||
import type { LudusaviPlatformEntryCreateOrConnectWithoutLudusaviEntryInput } from "~/prisma/client/models";
|
import type { LudusaviPlatformEntryCreateOrConnectWithoutLudusaviEntryInput } from "~/prisma/client/models";
|
||||||
|
import prisma from "../../db/database";
|
||||||
|
|
||||||
type ConnectOrCreateShorthand =
|
type ConnectOrCreateShorthand =
|
||||||
LudusaviPlatformEntryCreateOrConnectWithoutLudusaviEntryInput;
|
LudusaviPlatformEntryCreateOrConnectWithoutLudusaviEntryInput;
|
||||||
@ -19,17 +20,25 @@ type LudusaviModel = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export default defineTask({
|
export default defineDropTask({
|
||||||
async run(_event) {
|
buildId: () => `ludusavi:import:${new Date().toISOString()}`,
|
||||||
|
name: "Import Ludusavi",
|
||||||
|
acls: [],
|
||||||
|
taskGroup: "ludusavi:import",
|
||||||
|
async run({ log, progress }) {
|
||||||
const manifest = yaml.load(
|
const manifest = yaml.load(
|
||||||
await $fetch<string>(
|
await $fetch<string>(
|
||||||
"https://raw.githubusercontent.com/mtkennerly/ludusavi-manifest/refs/heads/master/data/manifest.yaml",
|
"https://raw.githubusercontent.com/mtkennerly/ludusavi-manifest/refs/heads/master/data/manifest.yaml",
|
||||||
),
|
),
|
||||||
) as LudusaviModel;
|
) 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;
|
if (!data.files && !data.registry) continue;
|
||||||
console.log(name);
|
|
||||||
|
|
||||||
const iterableFiles = data.files ? Object.entries(data.files) : undefined;
|
const iterableFiles = data.files ? Object.entries(data.files) : undefined;
|
||||||
|
|
||||||
@ -126,8 +135,9 @@ export default defineTask({
|
|||||||
entries: { connectOrCreate },
|
entries: { connectOrCreate },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
return { result: true };
|
currentProgress += increment;
|
||||||
|
log(`Imported game "${name}"`);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user