@mdfriday/foundry 26.2.8 → 26.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/worker/pool-manager.js +141 -27
- package/dist/worker/worker-node.js +141 -27
- package/package.json +1 -1
|
@@ -95285,6 +95285,7 @@ function createTaskBatches(tasks2, batchSize) {
|
|
|
95285
95285
|
}
|
|
95286
95286
|
async function runWorkerLoop(poolManager, taskQueue, workerIndex, totalPages, completedPages, onProgress) {
|
|
95287
95287
|
const results = [];
|
|
95288
|
+
log58.debug(`\u{1F680} Worker ${workerIndex} loop started`);
|
|
95288
95289
|
while (true) {
|
|
95289
95290
|
const batch = taskQueue.nextBatch();
|
|
95290
95291
|
if (!batch) {
|
|
@@ -95298,7 +95299,16 @@ async function runWorkerLoop(poolManager, taskQueue, workerIndex, totalPages, co
|
|
|
95298
95299
|
pageTasks: batch
|
|
95299
95300
|
// ⭐ 现在传递 PageTask[] 而不是 string[]
|
|
95300
95301
|
};
|
|
95302
|
+
log58.debug(`Worker ${workerIndex} sending task to pool manager`, {
|
|
95303
|
+
taskType: task.type,
|
|
95304
|
+
batchSize: batch.length
|
|
95305
|
+
});
|
|
95301
95306
|
const response = await poolManager.exec(task);
|
|
95307
|
+
log58.debug(`Worker ${workerIndex} received response`, {
|
|
95308
|
+
success: response.success,
|
|
95309
|
+
hasData: !!response.data,
|
|
95310
|
+
error: response.error
|
|
95311
|
+
});
|
|
95302
95312
|
if (response.success && response.data) {
|
|
95303
95313
|
const result = response.data;
|
|
95304
95314
|
results.push(result);
|
|
@@ -95316,6 +95326,10 @@ async function runWorkerLoop(poolManager, taskQueue, workerIndex, totalPages, co
|
|
|
95316
95326
|
log58.info(`\u2705 Worker ${workerIndex} completed batch: ${result.processedCount} tasks in ${result.duration.toFixed(2)}ms`);
|
|
95317
95327
|
} else {
|
|
95318
95328
|
log58.error(`\u274C Worker ${workerIndex} failed: ${response.error}`);
|
|
95329
|
+
log58.debug(`Worker ${workerIndex} error details:`, {
|
|
95330
|
+
batchSize: batch.length,
|
|
95331
|
+
error: response.error
|
|
95332
|
+
});
|
|
95319
95333
|
results.push({
|
|
95320
95334
|
success: false,
|
|
95321
95335
|
processedCount: 0,
|
|
@@ -95325,6 +95339,7 @@ async function runWorkerLoop(poolManager, taskQueue, workerIndex, totalPages, co
|
|
|
95325
95339
|
});
|
|
95326
95340
|
}
|
|
95327
95341
|
}
|
|
95342
|
+
log58.debug(`Worker ${workerIndex} loop completed, processed ${results.length} batches`);
|
|
95328
95343
|
return results;
|
|
95329
95344
|
}
|
|
95330
95345
|
async function processSSGParallel(projDir, modulesDir, markdown, onProgress, httpClient) {
|
|
@@ -95385,15 +95400,27 @@ async function processSSGParallel(projDir, modulesDir, markdown, onProgress, htt
|
|
|
95385
95400
|
const initStartTime = performance.now();
|
|
95386
95401
|
const initTasks = [];
|
|
95387
95402
|
for (let i = 0; i < workerCount; i++) {
|
|
95403
|
+
log58.debug(`Creating init task for worker ${i}`);
|
|
95388
95404
|
const initTask = {
|
|
95389
95405
|
type: "init",
|
|
95390
95406
|
projDir,
|
|
95391
95407
|
moduleDir: modulesDir
|
|
95392
95408
|
};
|
|
95393
|
-
|
|
95409
|
+
const initPromise = poolManager.exec(initTask);
|
|
95410
|
+
initPromise.then(
|
|
95411
|
+
(result) => log58.debug(`Worker ${i} init result:`, { success: result.success, error: result.error }),
|
|
95412
|
+
(error) => log58.error(`Worker ${i} init failed:`, error)
|
|
95413
|
+
);
|
|
95414
|
+
initTasks.push(initPromise);
|
|
95394
95415
|
}
|
|
95395
|
-
|
|
95416
|
+
log58.info(`Waiting for ${workerCount} workers to initialize...`);
|
|
95417
|
+
const initResults = await Promise.all(initTasks);
|
|
95396
95418
|
const initDuration = performance.now() - initStartTime;
|
|
95419
|
+
const failedInits = initResults.filter((r) => !r.success);
|
|
95420
|
+
if (failedInits.length > 0) {
|
|
95421
|
+
log58.error(`\u274C ${failedInits.length} workers failed to initialize:`, failedInits);
|
|
95422
|
+
throw new Error(`Failed to initialize ${failedInits.length} workers: ${failedInits.map((r) => r.error).join(", ")}`);
|
|
95423
|
+
}
|
|
95397
95424
|
log58.info(`\u2705 All workers initialized in ${initDuration.toFixed(2)}ms`);
|
|
95398
95425
|
onProgress?.({
|
|
95399
95426
|
stage: "build",
|
|
@@ -96214,17 +96241,29 @@ var init_worker_state = __esm({
|
|
|
96214
96241
|
|
|
96215
96242
|
// internal/application/worker/worker-main.ts
|
|
96216
96243
|
async function handleWorkerTask(task) {
|
|
96244
|
+
log61.info(`\u{1F528} handleWorkerTask called with task type: ${task.type}`);
|
|
96245
|
+
log61.debug("Task details:", {
|
|
96246
|
+
type: task.type,
|
|
96247
|
+
hasProjDir: !!task.projDir,
|
|
96248
|
+
hasModuleDir: !!task.moduleDir,
|
|
96249
|
+
pageTasksCount: task.pageTasks?.length || 0
|
|
96250
|
+
});
|
|
96217
96251
|
try {
|
|
96218
96252
|
switch (task.type) {
|
|
96219
96253
|
case "init":
|
|
96254
|
+
log61.debug("Handling init task");
|
|
96220
96255
|
return await handleInit(task);
|
|
96221
96256
|
case "process-batch":
|
|
96257
|
+
log61.debug("Handling process-batch task");
|
|
96222
96258
|
return await handleProcessBatch(task);
|
|
96223
96259
|
case "stats":
|
|
96260
|
+
log61.debug("Handling stats task");
|
|
96224
96261
|
return await handleStats();
|
|
96225
96262
|
case "cleanup":
|
|
96263
|
+
log61.debug("Handling cleanup task");
|
|
96226
96264
|
return await handleCleanup();
|
|
96227
96265
|
default:
|
|
96266
|
+
log61.error(`Unknown task type: ${task.type}`);
|
|
96228
96267
|
return {
|
|
96229
96268
|
success: false,
|
|
96230
96269
|
error: `Unknown task type: ${task.type}`
|
|
@@ -96232,7 +96271,9 @@ async function handleWorkerTask(task) {
|
|
|
96232
96271
|
}
|
|
96233
96272
|
} catch (error) {
|
|
96234
96273
|
const message = error instanceof Error ? error.message : String(error);
|
|
96235
|
-
|
|
96274
|
+
const stack = error instanceof Error ? error.stack : void 0;
|
|
96275
|
+
log61.error(`\u274C Worker task failed: ${message}`);
|
|
96276
|
+
log61.debug("Error stack:", stack);
|
|
96236
96277
|
return {
|
|
96237
96278
|
success: false,
|
|
96238
96279
|
error: message
|
|
@@ -96240,39 +96281,68 @@ async function handleWorkerTask(task) {
|
|
|
96240
96281
|
}
|
|
96241
96282
|
}
|
|
96242
96283
|
async function handleInit(task) {
|
|
96284
|
+
log61.info("\u{1F527} handleInit called");
|
|
96285
|
+
log61.debug("Init task params:", {
|
|
96286
|
+
projDir: task.projDir,
|
|
96287
|
+
moduleDir: task.moduleDir
|
|
96288
|
+
});
|
|
96243
96289
|
if (!task.projDir || !task.moduleDir) {
|
|
96290
|
+
log61.error("Missing required parameters for init");
|
|
96244
96291
|
return {
|
|
96245
96292
|
success: false,
|
|
96246
96293
|
error: "Missing projDir or moduleDir for init task"
|
|
96247
96294
|
};
|
|
96248
96295
|
}
|
|
96249
|
-
|
|
96250
|
-
|
|
96251
|
-
|
|
96252
|
-
|
|
96253
|
-
|
|
96254
|
-
|
|
96255
|
-
|
|
96296
|
+
try {
|
|
96297
|
+
log61.info("Creating WorkerState...");
|
|
96298
|
+
workerState = new WorkerState(task.projDir, task.moduleDir);
|
|
96299
|
+
log61.info("Initializing WorkerState...");
|
|
96300
|
+
await workerState.initialize();
|
|
96301
|
+
log61.info("\u2705 Worker initialized successfully");
|
|
96302
|
+
return {
|
|
96303
|
+
success: true,
|
|
96304
|
+
data: { message: "Worker initialized successfully" }
|
|
96305
|
+
};
|
|
96306
|
+
} catch (error) {
|
|
96307
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
96308
|
+
log61.error(`Failed to initialize worker: ${message}`);
|
|
96309
|
+
throw error;
|
|
96310
|
+
}
|
|
96256
96311
|
}
|
|
96257
96312
|
async function handleProcessBatch(task) {
|
|
96313
|
+
log61.info("\u{1F4E6} handleProcessBatch called");
|
|
96258
96314
|
if (!workerState) {
|
|
96315
|
+
log61.error("Worker not initialized");
|
|
96259
96316
|
return {
|
|
96260
96317
|
success: false,
|
|
96261
96318
|
error: "Worker not initialized. Call init task first."
|
|
96262
96319
|
};
|
|
96263
96320
|
}
|
|
96264
96321
|
if (!task.pageTasks || task.pageTasks.length === 0) {
|
|
96322
|
+
log61.error("Missing pageTasks");
|
|
96265
96323
|
return {
|
|
96266
96324
|
success: false,
|
|
96267
96325
|
error: "Missing pageTasks for process-batch task"
|
|
96268
96326
|
};
|
|
96269
96327
|
}
|
|
96270
|
-
|
|
96271
|
-
|
|
96272
|
-
|
|
96273
|
-
|
|
96274
|
-
|
|
96275
|
-
|
|
96328
|
+
log61.info(`Processing batch of ${task.pageTasks.length} tasks...`);
|
|
96329
|
+
try {
|
|
96330
|
+
const result = await workerState.processBatch(task.pageTasks);
|
|
96331
|
+
log61.info(`\u2705 Batch processed: ${result.processedCount}/${result.totalCount} pages`, {
|
|
96332
|
+
success: result.success,
|
|
96333
|
+
duration: result.duration,
|
|
96334
|
+
errorCount: result.errors.length
|
|
96335
|
+
});
|
|
96336
|
+
return {
|
|
96337
|
+
success: result.success,
|
|
96338
|
+
data: result,
|
|
96339
|
+
error: result.errors.length > 0 ? result.errors.join("; ") : void 0
|
|
96340
|
+
};
|
|
96341
|
+
} catch (error) {
|
|
96342
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
96343
|
+
log61.error(`Failed to process batch: ${message}`);
|
|
96344
|
+
throw error;
|
|
96345
|
+
}
|
|
96276
96346
|
}
|
|
96277
96347
|
async function handleStats() {
|
|
96278
96348
|
if (!workerState) {
|
|
@@ -96434,19 +96504,34 @@ var init_pool_manager = __esm({
|
|
|
96434
96504
|
/**
|
|
96435
96505
|
* 初始化浏览器 Worker 池
|
|
96436
96506
|
*
|
|
96437
|
-
*
|
|
96438
|
-
* workerpool 会自动将函数序列化并在 Worker 中执行
|
|
96507
|
+
* 在浏览器/Electron 环境中,workerpool 会自动创建 Web Workers
|
|
96439
96508
|
*/
|
|
96440
96509
|
async initializeBrowserPool() {
|
|
96441
|
-
|
|
96442
|
-
|
|
96443
|
-
|
|
96444
|
-
|
|
96445
|
-
|
|
96446
|
-
|
|
96447
|
-
|
|
96448
|
-
log62.debug(`Browser worker pool created with ${this.workerCount} workers`);
|
|
96510
|
+
log62.info("\u{1F310} Initializing browser worker pool...");
|
|
96511
|
+
const hasWorker = typeof Worker !== "undefined";
|
|
96512
|
+
log62.debug("Browser environment details:", {
|
|
96513
|
+
hasWorker,
|
|
96514
|
+
hasWindow: typeof globalThis.window !== "undefined",
|
|
96515
|
+
hasNavigator: typeof navigator !== "undefined",
|
|
96516
|
+
hardwareConcurrency: typeof navigator !== "undefined" ? navigator.hardwareConcurrency : "N/A"
|
|
96449
96517
|
});
|
|
96518
|
+
try {
|
|
96519
|
+
this.pool = workerpool.pool({
|
|
96520
|
+
minWorkers: this.workerCount,
|
|
96521
|
+
maxWorkers: this.workerCount,
|
|
96522
|
+
workerType: "web"
|
|
96523
|
+
});
|
|
96524
|
+
log62.info(`\u2705 Browser worker pool created with ${this.workerCount} workers`);
|
|
96525
|
+
log62.debug("Pool configuration:", {
|
|
96526
|
+
minWorkers: this.workerCount,
|
|
96527
|
+
maxWorkers: this.workerCount,
|
|
96528
|
+
workerType: "web"
|
|
96529
|
+
});
|
|
96530
|
+
} catch (error) {
|
|
96531
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
96532
|
+
log62.error(`Failed to create browser worker pool: ${message}`);
|
|
96533
|
+
throw error;
|
|
96534
|
+
}
|
|
96450
96535
|
}
|
|
96451
96536
|
/**
|
|
96452
96537
|
* 执行 Worker 任务
|
|
@@ -96455,17 +96540,46 @@ var init_pool_manager = __esm({
|
|
|
96455
96540
|
if (!this.pool) {
|
|
96456
96541
|
throw new Error("Worker pool not initialized. Call initialize() first.");
|
|
96457
96542
|
}
|
|
96543
|
+
log62.debug(`\u{1F4E4} Executing worker task: ${task.type}`, {
|
|
96544
|
+
environment: this.environment,
|
|
96545
|
+
taskType: task.type,
|
|
96546
|
+
hasProjectDir: !!task.projDir,
|
|
96547
|
+
hasModuleDir: !!task.moduleDir,
|
|
96548
|
+
pageTasksCount: task.pageTasks?.length || 0
|
|
96549
|
+
});
|
|
96458
96550
|
try {
|
|
96459
96551
|
if (this.environment === "node") {
|
|
96552
|
+
log62.debug("\u{1F527} Using Node.js worker (processTask function)");
|
|
96460
96553
|
const response = await this.pool.exec("processTask", [task]);
|
|
96554
|
+
log62.debug("\u{1F4E5} Node worker response received", { success: response.success });
|
|
96461
96555
|
return response;
|
|
96462
96556
|
} else {
|
|
96557
|
+
log62.debug("\u{1F310} Using browser worker (handleWorkerTask function)");
|
|
96558
|
+
log62.debug("handleWorkerTask type:", typeof handleWorkerTask);
|
|
96559
|
+
log62.debug("Task being sent to worker:", JSON.stringify({
|
|
96560
|
+
type: task.type,
|
|
96561
|
+
projDir: task.projDir,
|
|
96562
|
+
moduleDir: task.moduleDir,
|
|
96563
|
+
pageTasksCount: task.pageTasks?.length
|
|
96564
|
+
}));
|
|
96463
96565
|
const response = await this.pool.exec(handleWorkerTask, [task]);
|
|
96566
|
+
log62.debug("\u{1F4E5} Browser worker response received", {
|
|
96567
|
+
success: response.success,
|
|
96568
|
+
hasData: !!response.data,
|
|
96569
|
+
error: response.error
|
|
96570
|
+
});
|
|
96464
96571
|
return response;
|
|
96465
96572
|
}
|
|
96466
96573
|
} catch (error) {
|
|
96467
96574
|
const message = error instanceof Error ? error.message : String(error);
|
|
96468
|
-
|
|
96575
|
+
const stack = error instanceof Error ? error.stack : void 0;
|
|
96576
|
+
log62.error(`\u274C Worker task execution failed: ${message}`);
|
|
96577
|
+
log62.debug("Error details:", {
|
|
96578
|
+
message,
|
|
96579
|
+
stack,
|
|
96580
|
+
environment: this.environment,
|
|
96581
|
+
taskType: task.type
|
|
96582
|
+
});
|
|
96469
96583
|
return {
|
|
96470
96584
|
success: false,
|
|
96471
96585
|
error: message
|
|
@@ -95332,19 +95332,34 @@ var init_pool_manager = __esm({
|
|
|
95332
95332
|
/**
|
|
95333
95333
|
* 初始化浏览器 Worker 池
|
|
95334
95334
|
*
|
|
95335
|
-
*
|
|
95336
|
-
* workerpool 会自动将函数序列化并在 Worker 中执行
|
|
95335
|
+
* 在浏览器/Electron 环境中,workerpool 会自动创建 Web Workers
|
|
95337
95336
|
*/
|
|
95338
95337
|
async initializeBrowserPool() {
|
|
95339
|
-
|
|
95340
|
-
|
|
95341
|
-
|
|
95342
|
-
|
|
95343
|
-
|
|
95344
|
-
|
|
95345
|
-
|
|
95346
|
-
log57.debug(`Browser worker pool created with ${this.workerCount} workers`);
|
|
95338
|
+
log57.info("\u{1F310} Initializing browser worker pool...");
|
|
95339
|
+
const hasWorker = typeof Worker !== "undefined";
|
|
95340
|
+
log57.debug("Browser environment details:", {
|
|
95341
|
+
hasWorker,
|
|
95342
|
+
hasWindow: typeof globalThis.window !== "undefined",
|
|
95343
|
+
hasNavigator: typeof navigator !== "undefined",
|
|
95344
|
+
hardwareConcurrency: typeof navigator !== "undefined" ? navigator.hardwareConcurrency : "N/A"
|
|
95347
95345
|
});
|
|
95346
|
+
try {
|
|
95347
|
+
this.pool = workerpool.pool({
|
|
95348
|
+
minWorkers: this.workerCount,
|
|
95349
|
+
maxWorkers: this.workerCount,
|
|
95350
|
+
workerType: "web"
|
|
95351
|
+
});
|
|
95352
|
+
log57.info(`\u2705 Browser worker pool created with ${this.workerCount} workers`);
|
|
95353
|
+
log57.debug("Pool configuration:", {
|
|
95354
|
+
minWorkers: this.workerCount,
|
|
95355
|
+
maxWorkers: this.workerCount,
|
|
95356
|
+
workerType: "web"
|
|
95357
|
+
});
|
|
95358
|
+
} catch (error) {
|
|
95359
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
95360
|
+
log57.error(`Failed to create browser worker pool: ${message}`);
|
|
95361
|
+
throw error;
|
|
95362
|
+
}
|
|
95348
95363
|
}
|
|
95349
95364
|
/**
|
|
95350
95365
|
* 执行 Worker 任务
|
|
@@ -95353,17 +95368,46 @@ var init_pool_manager = __esm({
|
|
|
95353
95368
|
if (!this.pool) {
|
|
95354
95369
|
throw new Error("Worker pool not initialized. Call initialize() first.");
|
|
95355
95370
|
}
|
|
95371
|
+
log57.debug(`\u{1F4E4} Executing worker task: ${task.type}`, {
|
|
95372
|
+
environment: this.environment,
|
|
95373
|
+
taskType: task.type,
|
|
95374
|
+
hasProjectDir: !!task.projDir,
|
|
95375
|
+
hasModuleDir: !!task.moduleDir,
|
|
95376
|
+
pageTasksCount: task.pageTasks?.length || 0
|
|
95377
|
+
});
|
|
95356
95378
|
try {
|
|
95357
95379
|
if (this.environment === "node") {
|
|
95380
|
+
log57.debug("\u{1F527} Using Node.js worker (processTask function)");
|
|
95358
95381
|
const response = await this.pool.exec("processTask", [task]);
|
|
95382
|
+
log57.debug("\u{1F4E5} Node worker response received", { success: response.success });
|
|
95359
95383
|
return response;
|
|
95360
95384
|
} else {
|
|
95385
|
+
log57.debug("\u{1F310} Using browser worker (handleWorkerTask function)");
|
|
95386
|
+
log57.debug("handleWorkerTask type:", typeof handleWorkerTask);
|
|
95387
|
+
log57.debug("Task being sent to worker:", JSON.stringify({
|
|
95388
|
+
type: task.type,
|
|
95389
|
+
projDir: task.projDir,
|
|
95390
|
+
moduleDir: task.moduleDir,
|
|
95391
|
+
pageTasksCount: task.pageTasks?.length
|
|
95392
|
+
}));
|
|
95361
95393
|
const response = await this.pool.exec(handleWorkerTask, [task]);
|
|
95394
|
+
log57.debug("\u{1F4E5} Browser worker response received", {
|
|
95395
|
+
success: response.success,
|
|
95396
|
+
hasData: !!response.data,
|
|
95397
|
+
error: response.error
|
|
95398
|
+
});
|
|
95362
95399
|
return response;
|
|
95363
95400
|
}
|
|
95364
95401
|
} catch (error) {
|
|
95365
95402
|
const message = error instanceof Error ? error.message : String(error);
|
|
95366
|
-
|
|
95403
|
+
const stack = error instanceof Error ? error.stack : void 0;
|
|
95404
|
+
log57.error(`\u274C Worker task execution failed: ${message}`);
|
|
95405
|
+
log57.debug("Error details:", {
|
|
95406
|
+
message,
|
|
95407
|
+
stack,
|
|
95408
|
+
environment: this.environment,
|
|
95409
|
+
taskType: task.type
|
|
95410
|
+
});
|
|
95367
95411
|
return {
|
|
95368
95412
|
success: false,
|
|
95369
95413
|
error: message
|
|
@@ -95472,6 +95516,7 @@ function createTaskBatches(tasks2, batchSize) {
|
|
|
95472
95516
|
}
|
|
95473
95517
|
async function runWorkerLoop(poolManager, taskQueue, workerIndex, totalPages, completedPages, onProgress) {
|
|
95474
95518
|
const results = [];
|
|
95519
|
+
log59.debug(`\u{1F680} Worker ${workerIndex} loop started`);
|
|
95475
95520
|
while (true) {
|
|
95476
95521
|
const batch = taskQueue.nextBatch();
|
|
95477
95522
|
if (!batch) {
|
|
@@ -95485,7 +95530,16 @@ async function runWorkerLoop(poolManager, taskQueue, workerIndex, totalPages, co
|
|
|
95485
95530
|
pageTasks: batch
|
|
95486
95531
|
// ⭐ 现在传递 PageTask[] 而不是 string[]
|
|
95487
95532
|
};
|
|
95533
|
+
log59.debug(`Worker ${workerIndex} sending task to pool manager`, {
|
|
95534
|
+
taskType: task.type,
|
|
95535
|
+
batchSize: batch.length
|
|
95536
|
+
});
|
|
95488
95537
|
const response = await poolManager.exec(task);
|
|
95538
|
+
log59.debug(`Worker ${workerIndex} received response`, {
|
|
95539
|
+
success: response.success,
|
|
95540
|
+
hasData: !!response.data,
|
|
95541
|
+
error: response.error
|
|
95542
|
+
});
|
|
95489
95543
|
if (response.success && response.data) {
|
|
95490
95544
|
const result = response.data;
|
|
95491
95545
|
results.push(result);
|
|
@@ -95503,6 +95557,10 @@ async function runWorkerLoop(poolManager, taskQueue, workerIndex, totalPages, co
|
|
|
95503
95557
|
log59.info(`\u2705 Worker ${workerIndex} completed batch: ${result.processedCount} tasks in ${result.duration.toFixed(2)}ms`);
|
|
95504
95558
|
} else {
|
|
95505
95559
|
log59.error(`\u274C Worker ${workerIndex} failed: ${response.error}`);
|
|
95560
|
+
log59.debug(`Worker ${workerIndex} error details:`, {
|
|
95561
|
+
batchSize: batch.length,
|
|
95562
|
+
error: response.error
|
|
95563
|
+
});
|
|
95506
95564
|
results.push({
|
|
95507
95565
|
success: false,
|
|
95508
95566
|
processedCount: 0,
|
|
@@ -95512,6 +95570,7 @@ async function runWorkerLoop(poolManager, taskQueue, workerIndex, totalPages, co
|
|
|
95512
95570
|
});
|
|
95513
95571
|
}
|
|
95514
95572
|
}
|
|
95573
|
+
log59.debug(`Worker ${workerIndex} loop completed, processed ${results.length} batches`);
|
|
95515
95574
|
return results;
|
|
95516
95575
|
}
|
|
95517
95576
|
async function processSSGParallel(projDir, modulesDir, markdown, onProgress, httpClient) {
|
|
@@ -95572,15 +95631,27 @@ async function processSSGParallel(projDir, modulesDir, markdown, onProgress, htt
|
|
|
95572
95631
|
const initStartTime = performance.now();
|
|
95573
95632
|
const initTasks = [];
|
|
95574
95633
|
for (let i = 0; i < workerCount; i++) {
|
|
95634
|
+
log59.debug(`Creating init task for worker ${i}`);
|
|
95575
95635
|
const initTask = {
|
|
95576
95636
|
type: "init",
|
|
95577
95637
|
projDir,
|
|
95578
95638
|
moduleDir: modulesDir
|
|
95579
95639
|
};
|
|
95580
|
-
|
|
95640
|
+
const initPromise = poolManager.exec(initTask);
|
|
95641
|
+
initPromise.then(
|
|
95642
|
+
(result) => log59.debug(`Worker ${i} init result:`, { success: result.success, error: result.error }),
|
|
95643
|
+
(error) => log59.error(`Worker ${i} init failed:`, error)
|
|
95644
|
+
);
|
|
95645
|
+
initTasks.push(initPromise);
|
|
95581
95646
|
}
|
|
95582
|
-
|
|
95647
|
+
log59.info(`Waiting for ${workerCount} workers to initialize...`);
|
|
95648
|
+
const initResults = await Promise.all(initTasks);
|
|
95583
95649
|
const initDuration = performance.now() - initStartTime;
|
|
95650
|
+
const failedInits = initResults.filter((r) => !r.success);
|
|
95651
|
+
if (failedInits.length > 0) {
|
|
95652
|
+
log59.error(`\u274C ${failedInits.length} workers failed to initialize:`, failedInits);
|
|
95653
|
+
throw new Error(`Failed to initialize ${failedInits.length} workers: ${failedInits.map((r) => r.error).join(", ")}`);
|
|
95654
|
+
}
|
|
95584
95655
|
log59.info(`\u2705 All workers initialized in ${initDuration.toFixed(2)}ms`);
|
|
95585
95656
|
onProgress?.({
|
|
95586
95657
|
stage: "build",
|
|
@@ -96401,17 +96472,29 @@ var init_worker_state = __esm({
|
|
|
96401
96472
|
|
|
96402
96473
|
// internal/application/worker/worker-main.ts
|
|
96403
96474
|
async function handleWorkerTask(task) {
|
|
96475
|
+
log62.info(`\u{1F528} handleWorkerTask called with task type: ${task.type}`);
|
|
96476
|
+
log62.debug("Task details:", {
|
|
96477
|
+
type: task.type,
|
|
96478
|
+
hasProjDir: !!task.projDir,
|
|
96479
|
+
hasModuleDir: !!task.moduleDir,
|
|
96480
|
+
pageTasksCount: task.pageTasks?.length || 0
|
|
96481
|
+
});
|
|
96404
96482
|
try {
|
|
96405
96483
|
switch (task.type) {
|
|
96406
96484
|
case "init":
|
|
96485
|
+
log62.debug("Handling init task");
|
|
96407
96486
|
return await handleInit(task);
|
|
96408
96487
|
case "process-batch":
|
|
96488
|
+
log62.debug("Handling process-batch task");
|
|
96409
96489
|
return await handleProcessBatch(task);
|
|
96410
96490
|
case "stats":
|
|
96491
|
+
log62.debug("Handling stats task");
|
|
96411
96492
|
return await handleStats();
|
|
96412
96493
|
case "cleanup":
|
|
96494
|
+
log62.debug("Handling cleanup task");
|
|
96413
96495
|
return await handleCleanup();
|
|
96414
96496
|
default:
|
|
96497
|
+
log62.error(`Unknown task type: ${task.type}`);
|
|
96415
96498
|
return {
|
|
96416
96499
|
success: false,
|
|
96417
96500
|
error: `Unknown task type: ${task.type}`
|
|
@@ -96419,7 +96502,9 @@ async function handleWorkerTask(task) {
|
|
|
96419
96502
|
}
|
|
96420
96503
|
} catch (error) {
|
|
96421
96504
|
const message = error instanceof Error ? error.message : String(error);
|
|
96422
|
-
|
|
96505
|
+
const stack = error instanceof Error ? error.stack : void 0;
|
|
96506
|
+
log62.error(`\u274C Worker task failed: ${message}`);
|
|
96507
|
+
log62.debug("Error stack:", stack);
|
|
96423
96508
|
return {
|
|
96424
96509
|
success: false,
|
|
96425
96510
|
error: message
|
|
@@ -96427,39 +96512,68 @@ async function handleWorkerTask(task) {
|
|
|
96427
96512
|
}
|
|
96428
96513
|
}
|
|
96429
96514
|
async function handleInit(task) {
|
|
96515
|
+
log62.info("\u{1F527} handleInit called");
|
|
96516
|
+
log62.debug("Init task params:", {
|
|
96517
|
+
projDir: task.projDir,
|
|
96518
|
+
moduleDir: task.moduleDir
|
|
96519
|
+
});
|
|
96430
96520
|
if (!task.projDir || !task.moduleDir) {
|
|
96521
|
+
log62.error("Missing required parameters for init");
|
|
96431
96522
|
return {
|
|
96432
96523
|
success: false,
|
|
96433
96524
|
error: "Missing projDir or moduleDir for init task"
|
|
96434
96525
|
};
|
|
96435
96526
|
}
|
|
96436
|
-
|
|
96437
|
-
|
|
96438
|
-
|
|
96439
|
-
|
|
96440
|
-
|
|
96441
|
-
|
|
96442
|
-
|
|
96527
|
+
try {
|
|
96528
|
+
log62.info("Creating WorkerState...");
|
|
96529
|
+
workerState = new WorkerState(task.projDir, task.moduleDir);
|
|
96530
|
+
log62.info("Initializing WorkerState...");
|
|
96531
|
+
await workerState.initialize();
|
|
96532
|
+
log62.info("\u2705 Worker initialized successfully");
|
|
96533
|
+
return {
|
|
96534
|
+
success: true,
|
|
96535
|
+
data: { message: "Worker initialized successfully" }
|
|
96536
|
+
};
|
|
96537
|
+
} catch (error) {
|
|
96538
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
96539
|
+
log62.error(`Failed to initialize worker: ${message}`);
|
|
96540
|
+
throw error;
|
|
96541
|
+
}
|
|
96443
96542
|
}
|
|
96444
96543
|
async function handleProcessBatch(task) {
|
|
96544
|
+
log62.info("\u{1F4E6} handleProcessBatch called");
|
|
96445
96545
|
if (!workerState) {
|
|
96546
|
+
log62.error("Worker not initialized");
|
|
96446
96547
|
return {
|
|
96447
96548
|
success: false,
|
|
96448
96549
|
error: "Worker not initialized. Call init task first."
|
|
96449
96550
|
};
|
|
96450
96551
|
}
|
|
96451
96552
|
if (!task.pageTasks || task.pageTasks.length === 0) {
|
|
96553
|
+
log62.error("Missing pageTasks");
|
|
96452
96554
|
return {
|
|
96453
96555
|
success: false,
|
|
96454
96556
|
error: "Missing pageTasks for process-batch task"
|
|
96455
96557
|
};
|
|
96456
96558
|
}
|
|
96457
|
-
|
|
96458
|
-
|
|
96459
|
-
|
|
96460
|
-
|
|
96461
|
-
|
|
96462
|
-
|
|
96559
|
+
log62.info(`Processing batch of ${task.pageTasks.length} tasks...`);
|
|
96560
|
+
try {
|
|
96561
|
+
const result = await workerState.processBatch(task.pageTasks);
|
|
96562
|
+
log62.info(`\u2705 Batch processed: ${result.processedCount}/${result.totalCount} pages`, {
|
|
96563
|
+
success: result.success,
|
|
96564
|
+
duration: result.duration,
|
|
96565
|
+
errorCount: result.errors.length
|
|
96566
|
+
});
|
|
96567
|
+
return {
|
|
96568
|
+
success: result.success,
|
|
96569
|
+
data: result,
|
|
96570
|
+
error: result.errors.length > 0 ? result.errors.join("; ") : void 0
|
|
96571
|
+
};
|
|
96572
|
+
} catch (error) {
|
|
96573
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
96574
|
+
log62.error(`Failed to process batch: ${message}`);
|
|
96575
|
+
throw error;
|
|
96576
|
+
}
|
|
96463
96577
|
}
|
|
96464
96578
|
async function handleStats() {
|
|
96465
96579
|
if (!workerState) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdfriday/foundry",
|
|
3
|
-
"version": "26.2.
|
|
3
|
+
"version": "26.2.9",
|
|
4
4
|
"description": "The core engine of MDFriday. Convert Markdown and shortcodes into fully themed static sites – Hugo-style, powered by TypeScript.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|