checkpoint: before migrating to nuxt v4

This commit is contained in:
DecDuck
2025-09-20 08:58:58 +10:00
parent 0b9a715bf2
commit b4f9b77809
11 changed files with 1277 additions and 2313 deletions

View File

@ -13,6 +13,7 @@ import { type } from "arktype";
import pino from "pino";
import { logger } from "~/server/internal/logging";
import { Writable } from "node:stream";
import type { TaskRunContext } from "./utils";
// a task that has been run
type FinishedTask = {
@ -412,36 +413,6 @@ class TaskHandler {
}
}
export type TaskRunContext = {
progress: (progress: number) => void;
logger: typeof logger;
};
export function wrapTaskContext(
context: TaskRunContext,
options: { min: number; max: number; prefix: string },
): TaskRunContext {
const child = context.logger.child({
prefix: options.prefix,
});
return {
progress(progress) {
if (progress > 100 || progress < 0) {
logger.warn("[wrapTaskContext] progress must be between 0 and 100");
}
// I was too tired to figure this out
// https://stackoverflow.com/a/929107
const oldRange = 100;
const newRange = options.max - options.min;
const adjustedProgress = (progress * newRange) / oldRange + options.min;
return context.progress(adjustedProgress);
},
logger: child,
};
}
export interface Task {
id: string;
taskGroup: TaskGroup;
@ -484,31 +455,6 @@ export const TaskLog = type({
level: "string",
});
// /**
// * Create a log message with a timestamp in the format YYYY-MM-DD HH:mm:ss.SSS UTC
// * @param message
// * @returns
// */
// function msgWithTimestamp(message: string): string {
// const now = new Date();
// const pad = (n: number, width = 2) => n.toString().padStart(width, "0");
// const year = now.getUTCFullYear();
// const month = pad(now.getUTCMonth() + 1);
// const day = pad(now.getUTCDate());
// const hours = pad(now.getUTCHours());
// const minutes = pad(now.getUTCMinutes());
// const seconds = pad(now.getUTCSeconds());
// const milliseconds = pad(now.getUTCMilliseconds(), 3);
// const log: typeof TaskLog.infer = {
// timestamp: `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${milliseconds} UTC`,
// message,
// };
// return JSON.stringify(log);
// }
export function defineDropTask(buildTask: BuildTask): DropTask {
return {

View File

@ -0,0 +1,58 @@
import { logger } from "../logging";
export type TaskRunContext = {
progress: (progress: number) => void;
logger: typeof logger;
};
export function wrapTaskContext(
context: TaskRunContext,
options: { min: number; max: number; prefix: string },
): TaskRunContext {
const child = context.logger.child({
prefix: options.prefix,
});
return {
progress(progress) {
if (progress > 100 || progress < 0) {
logger.warn("[wrapTaskContext] progress must be between 0 and 100");
}
// I was too tired to figure this out
// https://stackoverflow.com/a/929107
const oldRange = 100;
const newRange = options.max - options.min;
const adjustedProgress = (progress * newRange) / oldRange + options.min;
return context.progress(adjustedProgress);
},
logger: child,
};
}
// /**
// * Create a log message with a timestamp in the format YYYY-MM-DD HH:mm:ss.SSS UTC
// * @param message
// * @returns
// */
// function msgWithTimestamp(message: string): string {
// const now = new Date();
// const pad = (n: number, width = 2) => n.toString().padStart(width, "0");
// const year = now.getUTCFullYear();
// const month = pad(now.getUTCMonth() + 1);
// const day = pad(now.getUTCDate());
// const hours = pad(now.getUTCHours());
// const minutes = pad(now.getUTCMinutes());
// const seconds = pad(now.getUTCSeconds());
// const milliseconds = pad(now.getUTCMilliseconds(), 3);
// const log: typeof TaskLog.infer = {
// timestamp: `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${milliseconds} UTC`,
// message,
// };
// return JSON.stringify(log);
// }