fix(POSTV1-01): 接入Worker生成任务消费链路
Dada P0-A isolated Windows CI / validate-and-package (push) Waiting to run
Dada P0-A isolated Windows CI / validate-and-package (push) Waiting to run
This commit is contained in:
@@ -2,6 +2,8 @@ import { parentPort } from "node:worker_threads";
|
|||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
|
|
||||||
import { WorkerAiCallGate } from "./ai-call-gate.js";
|
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 { readConfiguredLocalDataRoot } from "./runtime-config.js";
|
||||||
import { RetentionCleanup } from "./retention-cleanup.js";
|
import { RetentionCleanup } from "./retention-cleanup.js";
|
||||||
import { ProjectPurgeCleanup } from "./project-purge-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 retention: RetentionCleanup | undefined;
|
||||||
let projectCleanup: ProjectPurgeCleanup | undefined;
|
let projectCleanup: ProjectPurgeCleanup | undefined;
|
||||||
let retentionTimer: ReturnType<typeof setInterval> | undefined;
|
let retentionTimer: ReturnType<typeof setInterval> | undefined;
|
||||||
|
let processor: GenerationProcessor | undefined;
|
||||||
|
let generationTimer: ReturnType<typeof setInterval> | undefined;
|
||||||
const control = attachWorkerSupervisorControl(controlPipe, () => {
|
const control = attachWorkerSupervisorControl(controlPipe, () => {
|
||||||
clearInterval(keepAlive);
|
clearInterval(keepAlive);
|
||||||
if (retentionTimer) clearInterval(retentionTimer);
|
if (retentionTimer) clearInterval(retentionTimer);
|
||||||
retention?.close();
|
retention?.close();
|
||||||
projectCleanup?.close();
|
projectCleanup?.close();
|
||||||
|
if (generationTimer) clearInterval(generationTimer);
|
||||||
|
processor?.close();
|
||||||
storage?.close();
|
storage?.close();
|
||||||
});
|
});
|
||||||
let storageStatus: "active" | "unavailable" = "active";
|
let storageStatus: "active" | "unavailable" = "active";
|
||||||
@@ -45,6 +51,15 @@ if (!workerPort && process.argv.includes("--dada-credential-stdin")) {
|
|||||||
storage = new WorkerStorageStatus(databasePath);
|
storage = new WorkerStorageStatus(databasePath);
|
||||||
retention = new RetentionCleanup({ databasePath });
|
retention = new RetentionCleanup({ databasePath });
|
||||||
projectCleanup = new ProjectPurgeCleanup({ dataRoot, 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 = () => {
|
const runRetentionCleanup = () => {
|
||||||
try {
|
try {
|
||||||
retention?.purgeExpired();
|
retention?.purgeExpired();
|
||||||
@@ -71,6 +86,7 @@ if (!workerPort && process.argv.includes("--dada-credential-stdin")) {
|
|||||||
});
|
});
|
||||||
logger.write({ error_category: "none", status_category: "ready" });
|
logger.write({ error_category: "none", status_category: "ready" });
|
||||||
new WorkerAiCallGate({ getStorageStatus: () => storageStatus === "unavailable" ? storageStatus : (storage?.getStatus() ?? "unavailable"), logger });
|
new WorkerAiCallGate({ getStorageStatus: () => storageStatus === "unavailable" ? storageStatus : (storage?.getStatus() ?? "unavailable"), logger });
|
||||||
|
generationTimer = setInterval(() => { void processor?.processNext().catch(() => undefined); }, 250);
|
||||||
} catch {
|
} catch {
|
||||||
storageStatus = "unavailable";
|
storageStatus = "unavailable";
|
||||||
control.reportStatus("storage_unavailable");
|
control.reportStatus("storage_unavailable");
|
||||||
|
|||||||
Reference in New Issue
Block a user