fix(POSTV1-01): 接入Worker生成任务消费链路
Dada P0-A isolated Windows CI / validate-and-package (push) Waiting to run

This commit is contained in:
suyx
2026-08-05 11:24:14 +08:00
parent 3dca4ad77c
commit 1155a81c3b
+16
View File
@@ -2,6 +2,8 @@ import { parentPort } from "node:worker_threads";
import { join } from "node:path";
import { WorkerAiCallGate } from "./ai-call-gate.js";
import { MockGenerationAdapter } from "./ai-adapter-contract.js";
import { GenerationProcessor } from "./generation-processor.js";
import { readConfiguredLocalDataRoot } from "./runtime-config.js";
import { RetentionCleanup } from "./retention-cleanup.js";
import { ProjectPurgeCleanup } from "./project-purge-cleanup.js";
@@ -31,11 +33,15 @@ if (!workerPort && process.argv.includes("--dada-credential-stdin")) {
let retention: RetentionCleanup | undefined;
let projectCleanup: ProjectPurgeCleanup | undefined;
let retentionTimer: ReturnType<typeof setInterval> | undefined;
let processor: GenerationProcessor | undefined;
let generationTimer: ReturnType<typeof setInterval> | undefined;
const control = attachWorkerSupervisorControl(controlPipe, () => {
clearInterval(keepAlive);
if (retentionTimer) clearInterval(retentionTimer);
retention?.close();
projectCleanup?.close();
if (generationTimer) clearInterval(generationTimer);
processor?.close();
storage?.close();
});
let storageStatus: "active" | "unavailable" = "active";
@@ -45,6 +51,15 @@ if (!workerPort && process.argv.includes("--dada-credential-stdin")) {
storage = new WorkerStorageStatus(databasePath);
retention = new RetentionCleanup({ databasePath });
projectCleanup = new ProjectPurgeCleanup({ dataRoot, databasePath });
processor = new GenerationProcessor({
adapter: new MockGenerationAdapter({
status: "completed",
outputs: [{ bytes: Buffer.from("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=", "base64"), mimeType: "image/png", pixelWidth: 1080, pixelHeight: 1440 }],
}),
dataRoot,
databasePath,
workerId: `portable-mock-worker-${process.pid}`,
});
const runRetentionCleanup = () => {
try {
retention?.purgeExpired();
@@ -71,6 +86,7 @@ if (!workerPort && process.argv.includes("--dada-credential-stdin")) {
});
logger.write({ error_category: "none", status_category: "ready" });
new WorkerAiCallGate({ getStorageStatus: () => storageStatus === "unavailable" ? storageStatus : (storage?.getStatus() ?? "unavailable"), logger });
generationTimer = setInterval(() => { void processor?.processNext().catch(() => undefined); }, 250);
} catch {
storageStatus = "unavailable";
control.reportStatus("storage_unavailable");